001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.lookupable;
018:
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.Map;
023:
024: import javax.servlet.http.HttpServletRequest;
025:
026: import edu.iu.uis.eden.EdenConstants;
027: import edu.iu.uis.eden.KEWServiceLocator;
028: import edu.iu.uis.eden.export.ExportDataSet;
029: import edu.iu.uis.eden.export.ExportFormat;
030: import edu.iu.uis.eden.export.Exportable;
031: import edu.iu.uis.eden.plugin.attributes.WorkflowLookupable;
032: import edu.iu.uis.eden.routetemplate.RuleTemplate;
033: import edu.iu.uis.eden.routetemplate.RuleTemplateService;
034: import edu.iu.uis.eden.util.Utilities;
035:
036: /**
037: * A {@link WorkflowLookupable} implementation for {@link RuleTemplate}.
038: *
039: * @see RuleTemplate
040: * @see RuleTemplateService
041: *
042: * @author ewestfal
043: */
044: public class RuleTemplateLookupableImpl implements WorkflowLookupable,
045: Exportable {
046:
047: private List rows;
048: private static List columns = establishColumns();
049: private static final String title = "Rule Template Lookup";
050: private static final String returnLocation = "Lookup.do";
051:
052: private static final String RULE_TEMPLATE_FIELD_LABEL = "Name";
053: private static final String DESCRIPTION_FIELD_LABEL = "Description";
054:
055: private static final String RULE_TEMPLATE_FIELD_HELP = "";
056: private static final String DESCRIPTION_FIELD_HELP = "";
057:
058: private static final String RULE_TEMPLATE_PROPERTY_NAME = "ruleTemplateName";
059: private static final String DESCRIPTION_PROPERTY_NAME = "description";
060:
061: private static final String RULE_TEMPLATE_ID_PROPERTY_NAME = "ruleTemplate.ruleTemplateId";
062: private static final String BACK_LOCATION = "backLocation";
063: private static final String DOC_FORM_KEY = "docFormKey";
064:
065: public RuleTemplateLookupableImpl() {
066: rows = new ArrayList();
067:
068: List fields = new ArrayList();
069: fields.add(new Field(RULE_TEMPLATE_FIELD_LABEL,
070: RULE_TEMPLATE_FIELD_HELP, Field.TEXT, false,
071: RULE_TEMPLATE_PROPERTY_NAME, "", null, null));
072: rows.add(new Row(fields));
073:
074: fields = new ArrayList();
075: fields.add(new Field(DESCRIPTION_FIELD_LABEL,
076: DESCRIPTION_FIELD_HELP, Field.TEXT, false,
077: DESCRIPTION_PROPERTY_NAME, "", null, null));
078: rows.add(new Row(fields));
079: }
080:
081: private static List establishColumns() {
082: List columnList = new ArrayList();
083: columnList.add(new Column("Rule Template Id",
084: Column.COLUMN_IS_SORTABLE_VALUE, "ruleTemplateId"));
085: columnList.add(new Column("Rule Template Name",
086: Column.COLUMN_IS_SORTABLE_VALUE, "name"));
087: columnList.add(new Column("Rule Template Description",
088: Column.COLUMN_IS_SORTABLE_VALUE, "description"));
089: columnList
090: .add(new Column("Rule Template Delegate",
091: Column.COLUMN_IS_SORTABLE_VALUE,
092: "delegateTemplateName"));
093: columnList.add(new Column("Rule Template Actions",
094: Column.COLUMN_NOT_SORTABLE_VALUE,
095: "ruleTemplateActionsUrl"));
096: return columnList;
097: }
098:
099: public void changeIdToName(Map fieldValues) {
100:
101: }
102:
103: /**
104: * getSearchResults - searches for a fiscal organization information based on the criteria passed in by the map.
105: *
106: * @return Returns a list of FiscalOrganization objects that match the result.
107: */
108: public List getSearchResults(Map fieldValues, Map fieldConversions)
109: throws Exception {
110: String name = (String) fieldValues
111: .get(RULE_TEMPLATE_PROPERTY_NAME);
112: String description = (String) fieldValues
113: .get(DESCRIPTION_PROPERTY_NAME);
114: String backLocation = (String) fieldValues.get(BACK_LOCATION);
115: String docFormKey = (String) fieldValues.get(DOC_FORM_KEY);
116:
117: String ruleTemplateIdReturn = (String) fieldConversions
118: .get(RULE_TEMPLATE_ID_PROPERTY_NAME);
119:
120: RuleTemplateService ruleTemplateService = (RuleTemplateService) KEWServiceLocator
121: .getService(KEWServiceLocator.RULE_TEMPLATE_SERVICE);
122: RuleTemplate ruleTemplate = new RuleTemplate();
123:
124: if (name != null && !"".equals(name.trim())) {
125: name = name.replace('*', '%');
126: ruleTemplate.setName("%" + name.trim() + "%");
127: }
128:
129: if (description != null && !"".equals(description.trim())) {
130: description = description.replace('*', '%');
131: ruleTemplate.setDescription("%" + description.trim() + "%");
132: }
133:
134: Iterator ruleTemplates = ruleTemplateService
135: .findByRuleTemplate(ruleTemplate).iterator();
136: List displayList = new ArrayList();
137: while (ruleTemplates.hasNext()) {
138: RuleTemplate record = (RuleTemplate) ruleTemplates.next();
139:
140: StringBuffer returnUrl = new StringBuffer("<a href=\"");
141: returnUrl.append(backLocation).append(
142: "?methodToCall=refresh&docFormKey=").append(
143: docFormKey).append("&");
144: if (!Utilities.isEmpty(ruleTemplateIdReturn)) {
145: returnUrl.append(ruleTemplateIdReturn);
146: } else {
147: returnUrl.append(RULE_TEMPLATE_ID_PROPERTY_NAME);
148: }
149: returnUrl.append("=").append(record.getRuleTemplateId())
150: .append("\">return value</a>");
151: record.setReturnUrl(returnUrl.toString());
152:
153: displayList.add(record);
154: }
155: return displayList;
156: }
157:
158: public boolean checkForAdditionalFields(Map fieldValues,
159: HttpServletRequest request) throws Exception {
160: return false;
161: }
162:
163: public List getDefaultReturnType() {
164: List returnTypes = new ArrayList();
165: returnTypes.add(RULE_TEMPLATE_ID_PROPERTY_NAME);
166: return returnTypes;
167: }
168:
169: public String getNoReturnParams(Map fieldConversions) {
170: String ruleTemplateIdReturn = (String) fieldConversions
171: .get(RULE_TEMPLATE_ID_PROPERTY_NAME);
172: StringBuffer noReturnParams = new StringBuffer("&");
173: if (!Utilities.isEmpty(ruleTemplateIdReturn)) {
174: noReturnParams.append(ruleTemplateIdReturn);
175: } else {
176: noReturnParams.append(RULE_TEMPLATE_ID_PROPERTY_NAME);
177: }
178: noReturnParams.append("=&").append(RULE_TEMPLATE_PROPERTY_NAME)
179: .append("=");
180: return noReturnParams.toString();
181: }
182:
183: public String getLookupInstructions() {
184: return Utilities
185: .getApplicationConstant(EdenConstants.RULE_TEMPLATE_SEARCH_INSTRUCTION_KEY);
186: }
187:
188: public String getTitle() {
189: return title;
190: }
191:
192: public String getReturnLocation() {
193: return returnLocation;
194: }
195:
196: public List getColumns() {
197: return columns;
198: }
199:
200: public String getHtmlMenuBar() {
201: return ""; // "<a href=\"RuleTemplate.do\" >Create new Rule Template</a>";
202: }
203:
204: public List getRows() {
205: return rows;
206: }
207:
208: public ExportDataSet export(ExportFormat format,
209: Object exportCriteria) throws Exception {
210: List searchResults = (List) exportCriteria;
211: ExportDataSet dataSet = new ExportDataSet(format);
212: dataSet.getRuleTemplates().addAll(searchResults);
213: return dataSet;
214: }
215:
216: public List getSupportedExportFormats() {
217: return EdenConstants.STANDARD_FORMATS;
218: }
219:
220: }
|