001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2007
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.war.beans.admin.main;
034:
035: import com.flexive.faces.FxJsfUtils;
036: import com.flexive.faces.messages.FxFacesMsgErr;
037: import com.flexive.faces.messages.FxFacesMsgInfo;
038: import com.flexive.faces.model.FxResultSetDataModel;
039: import com.flexive.shared.EJBLookup;
040: import com.flexive.shared.interfaces.SearchEngine;
041: import com.flexive.shared.search.FxResultSet;
042: import com.flexive.shared.search.FxSQLSearchParams;
043: import com.flexive.war.beans.admin.content.ContentEditorBean;
044:
045: import javax.faces.event.ActionEvent;
046: import javax.faces.model.SelectItem;
047: import java.util.ArrayList;
048: import java.util.List;
049:
050: /**
051: * This Bean provides access the the sql search.
052: *
053: * @author Gregor Schober (gregor.schober@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
054: * @version $Rev: 138 $
055: */
056: public class SqlSearchBean {
057:
058: private String query;
059: private FxResultSet queryResult;
060: private FxResultSetDataModel dataModel;
061: private SearchEngine sqlSearchInterface;
062: private long briefcaseAclId;
063: private String briefcaseDescription;
064: private String briefcaseName;
065: private Boolean createBriefcase;
066: private String cacheMode;
067: final static String LAST_QUERY_CACHE = SqlSearchBean.class
068: + "_LAST_QUERY";
069: private String actionPk;
070:
071: public String getActionPk() {
072: return actionPk;
073: }
074:
075: public void setActionPk(String actionPk) {
076: ContentEditorBean ceb = (ContentEditorBean) FxJsfUtils
077: .getManagedBean("contentEditorBean");
078: String pk[] = actionPk.split("\\.");
079: ceb.setId(new Long(pk[0]));
080: ceb.setVersion(new Integer(pk[1]));
081: this .actionPk = actionPk;
082: }
083:
084: public String getQuery() {
085: if (query == null) {
086: query = (String) FxJsfUtils
087: .getSessionAttribute(LAST_QUERY_CACHE);
088: }
089: return query;
090: }
091:
092: public SqlSearchBean() {
093: sqlSearchInterface = EJBLookup.getSearchEngine();
094: createBriefcase = false;
095: }
096:
097: public void toggleCreateBriefcase(ActionEvent event) {
098: // nothing to do, this is just the event that the briefcase mode was toggled
099: }
100:
101: public FxResultSet getQueryResult() {
102: return queryResult;
103: }
104:
105: public void setQuery(String query) {
106: if (query == null) {
107: query = "";
108: }
109: this .query = query;
110: FxJsfUtils.setSessionAttribute(LAST_QUERY_CACHE, query);
111: }
112:
113: public String getCacheMode() {
114: return cacheMode;
115: }
116:
117: public void setCacheMode(String cacheMode) {
118: this .cacheMode = cacheMode;
119: }
120:
121: private FxSQLSearchParams.CacheMode _getCacheMode() {
122: try {
123: if (cacheMode == null || cacheMode.trim().length() == 0) {
124: return null;
125: }
126: return FxSQLSearchParams.CacheMode.getById(Integer
127: .valueOf(cacheMode));
128: } catch (Throwable t) {
129: return null;
130: }
131: }
132:
133: /**
134: * Getter for all available cache modes.
135: *
136: * @return all available cache modes
137: */
138: public List<SelectItem> getCacheModes() {
139: final List<SelectItem> result = new ArrayList<SelectItem>(
140: FxSQLSearchParams.CacheMode.values().length);
141: for (FxSQLSearchParams.CacheMode mode : FxSQLSearchParams.CacheMode
142: .values()) {
143: result.add(new SelectItem(String.valueOf(mode.getId()),
144: String.valueOf(mode)));
145: }
146: return result;
147: }
148:
149: public Boolean getCreateBriefcase() {
150: return createBriefcase;
151: }
152:
153: public void setCreateBriefcase(Boolean createBriefcase) {
154: this .createBriefcase = createBriefcase;
155: }
156:
157: public long getBriefcaseAclId() {
158: return briefcaseAclId;
159: }
160:
161: public void setBriefcaseAclId(long briefcaseAclId) {
162: this .briefcaseAclId = briefcaseAclId;
163: }
164:
165: public String getBriefcaseDescription() {
166: return briefcaseDescription;
167: }
168:
169: public void setBriefcaseDescription(String briefcaseDescription) {
170: this .briefcaseDescription = briefcaseDescription;
171: }
172:
173: public String getBriefcaseName() {
174: return briefcaseName;
175: }
176:
177: public void setBriefcaseName(String briefcaseName) {
178: this .briefcaseName = briefcaseName;
179: }
180:
181: public FxResultSetDataModel getDataModel() {
182: if (dataModel == null && getQueryResult() != null) {
183: dataModel = new FxResultSetDataModel(getQueryResult());
184: }
185: return dataModel;
186: }
187:
188: public String executeSearch() {
189: FxSQLSearchParams sp = new FxSQLSearchParams();
190: sp.setCacheMode(_getCacheMode());
191: try {
192: if (createBriefcase) {
193: sp.saveResultInBriefcase(briefcaseName,
194: briefcaseDescription, briefcaseAclId);
195: queryResult = sqlSearchInterface.search(query, 0,
196: Integer.MAX_VALUE, sp);
197: new FxFacesMsgInfo("Briefcase.nfo.created",
198: briefcaseName).addToContext();
199: } else {
200: queryResult = sqlSearchInterface.search(this .query, 0,
201: null, sp);
202: }
203: } catch (Exception exc) {
204: queryResult = null;
205: new FxFacesMsgErr(exc).addToContext();
206: } finally {
207: createBriefcase = false;
208: }
209: return "sqlSearch";
210: }
211: }
|