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.RuleAttribute;
033: import edu.iu.uis.eden.routetemplate.RuleAttributeService;
034: import edu.iu.uis.eden.util.KeyLabelPair;
035: import edu.iu.uis.eden.util.Utilities;
036:
037: /**
038: * A {@link WorkflowLookupable} implementation for {@link RuleAttribute}.
039: *
040: * @see RuleAttribute
041: * @see RuleAttributeService
042: *
043: * @author jhopf
044: */
045: public class RuleAttributeLookupableImpl implements WorkflowLookupable,
046: Exportable {
047:
048: private List rows;
049:
050: private static List columns = establishColumns();
051:
052: private static final String title = "Rule Attribute Lookup";
053:
054: private static final String returnLocation = "Lookup.do";
055:
056: private static final String NAME_FIELD_LABEL = "Name";
057:
058: private static final String CLASSNAME_FIELD_LABEL = "Class Name";
059:
060: private static final String TYPE_FIELD_LABEL = "Attribute Type";
061:
062: private static final String NAME_FIELD_HELP = "";
063:
064: private static final String CLASSNAME_FIELD_HELP = "";
065:
066: private static final String TYPE_FIELD_HELP = "";
067:
068: private static final String NAME_PROPERTY_NAME = "name";
069:
070: private static final String CLASSNAME_PROPERTY_NAME = "className";
071:
072: private static final String TYPE_PROPERTY_NAME = "type";
073:
074: private static final String RULE_ATTRIBUTE_ID_PROPERTY_NAME = "ruleAttribute.ruleAttributeId";
075:
076: private static final String BACK_LOCATION = "backLocation";
077:
078: private static final String DOC_FORM_KEY = "docFormKey";
079:
080: private static final String LOOKUP_INSTRUCTIONS = "Enter criteria to search for a rule attribute.";
081:
082: public RuleAttributeLookupableImpl() {
083:
084: rows = new ArrayList();
085:
086: List fields = new ArrayList();
087: fields.add(new Field(NAME_FIELD_LABEL, NAME_FIELD_HELP,
088: Field.TEXT, false, NAME_PROPERTY_NAME, "", null, null));
089: rows.add(new Row(fields));
090:
091: fields = new ArrayList();
092: fields.add(new Field(CLASSNAME_FIELD_LABEL,
093: CLASSNAME_FIELD_HELP, Field.TEXT, false,
094: CLASSNAME_PROPERTY_NAME, "", null, null));
095: rows.add(new Row(fields));
096:
097: List options = new ArrayList();
098: options.add(new KeyLabelPair("", "All"));
099: options.add(new KeyLabelPair(EdenConstants.RULE_ATTRIBUTE_TYPE,
100: "Rule Attribute"));
101: options.add(new KeyLabelPair(
102: EdenConstants.SEARCHABLE_ATTRIBUTE_TYPE,
103: "Searchable Attribute"));
104: options.add(new KeyLabelPair(
105: EdenConstants.RULE_XML_ATTRIBUTE_TYPE,
106: "Rule Xml Attribute"));
107: options.add(new KeyLabelPair(
108: EdenConstants.SEARCHABLE_XML_ATTRIBUTE_TYPE,
109: "Searchable Xml Attribute"));
110: options.add(new KeyLabelPair(
111: EdenConstants.EXTENSION_ATTRIBUTE_TYPE,
112: "Extension Attribute"));
113: options.add(new KeyLabelPair(
114: EdenConstants.EMAIL_ATTRIBUTE_TYPE, "Email Attribute"));
115: options.add(new KeyLabelPair(EdenConstants.NOTE_ATTRIBUTE_TYPE,
116: "Note Attribute"));
117: options.add(new KeyLabelPair(
118: EdenConstants.ACTION_LIST_ATTRIBUTE_TYPE,
119: "Action List Attribute"));
120: options.add(new KeyLabelPair(
121: EdenConstants.RULE_VALIDATION_ATTRIBUTE_TYPE,
122: "Rule Validation Attribute"));
123: options.add(new KeyLabelPair(
124: EdenConstants.SEARCH_GENERATOR_ATTRIBUTE_TYPE,
125: "Document Search Generator Attribute"));
126: options.add(new KeyLabelPair(
127: EdenConstants.SEARCH_RESULT_PROCESSOR_ATTRIBUTE_TYPE,
128: "Document Search Result Processor Attribute"));
129: options
130: .add(new KeyLabelPair(
131: EdenConstants.SEARCH_RESULT_XML_PROCESSOR_ATTRIBUTE_TYPE,
132: "Document Search Result Processor XML Attribute"));
133:
134: fields = new ArrayList();
135: fields.add(new Field(TYPE_FIELD_LABEL, TYPE_FIELD_HELP,
136: Field.DROPDOWN, false, TYPE_PROPERTY_NAME, "", options,
137: null));
138: rows.add(new Row(fields));
139:
140: //TODO row for type?
141:
142: }
143:
144: private static List establishColumns() {
145: List columnList = new ArrayList();
146: columnList.add(new Column("Rule Attribute Id",
147: Column.COLUMN_IS_SORTABLE_VALUE, "ruleAttributeId"));
148: columnList.add(new Column("Rule Attribute Name",
149: Column.COLUMN_IS_SORTABLE_VALUE, "name"));
150: columnList.add(new Column("Attribute Type",
151: Column.COLUMN_IS_SORTABLE_VALUE, "type"));
152: columnList.add(new Column("Rule Attribute Class",
153: Column.COLUMN_IS_SORTABLE_VALUE, "className"));
154: columnList.add(new Column("Rule Attribute Actions",
155: Column.COLUMN_NOT_SORTABLE_VALUE,
156: "ruleAttributeActionsUrl"));
157: return columnList;
158: }
159:
160: public void changeIdToName(Map fieldValues) {
161:
162: }
163:
164: /**
165: * getSearchResults - searches for a fiscal organization information based on the criteria passed in by the map.
166: *
167: * @return Returns a list of FiscalOrganization objects that match the result.
168: */
169: public List getSearchResults(Map fieldValues, Map fieldConversions)
170: throws Exception {
171: String name = (String) fieldValues.get(NAME_PROPERTY_NAME);
172: String className = (String) fieldValues
173: .get(CLASSNAME_PROPERTY_NAME);
174: String type = (String) fieldValues.get(TYPE_PROPERTY_NAME);
175: String backLocation = (String) fieldValues.get(BACK_LOCATION);
176: String docFormKey = (String) fieldValues.get(DOC_FORM_KEY);
177:
178: String ruleIdReturn = (String) fieldConversions
179: .get(RULE_ATTRIBUTE_ID_PROPERTY_NAME);
180:
181: RuleAttributeService ruleAttributeService = (RuleAttributeService) KEWServiceLocator
182: .getService(KEWServiceLocator.RULE_ATTRIBUTE_SERVICE);
183: RuleAttribute ruleAttribute = new RuleAttribute();
184:
185: if (name != null && !"".equals(name.trim())) {
186: name = name.replace('*', '%');
187: ruleAttribute.setName("%" + name.trim() + "%");
188: }
189:
190: if (className != null && !"".equals(className.trim())) {
191: className = className.replace('*', '%');
192: ruleAttribute.setClassName("%" + className.trim() + "%");
193: }
194:
195: if (type != null && !"".equals(type.trim())) {
196: type = type.replace('*', '%');
197: ruleAttribute.setType(type.trim());
198: //Logger.getLogger(RuleAttributeLookupableImpl.class).info("Setting type: " + ruleAttribute.getType());
199: }
200:
201: Iterator ruleAttributes = ruleAttributeService
202: .findByRuleAttribute(ruleAttribute).iterator();
203: List displayList = new ArrayList();
204: while (ruleAttributes.hasNext()) {
205: RuleAttribute record = (RuleAttribute) ruleAttributes
206: .next();
207:
208: StringBuffer returnUrl = new StringBuffer("<a href=\"");
209: returnUrl.append(backLocation).append(
210: "?methodToCall=refresh&docFormKey=").append(
211: docFormKey).append("&");
212: if (!Utilities.isEmpty(ruleIdReturn)) {
213: returnUrl.append(ruleIdReturn);
214: } else {
215: returnUrl.append(RULE_ATTRIBUTE_ID_PROPERTY_NAME);
216: }
217: returnUrl.append("=").append(record.getRuleAttributeId())
218: .append("\">return value</a>");
219: record.setReturnUrl(returnUrl.toString());
220: displayList.add(record);
221: }
222: return displayList;
223: }
224:
225: public boolean checkForAdditionalFields(Map fieldValues,
226: HttpServletRequest request) throws Exception {
227: return false;
228: }
229:
230: public List getDefaultReturnType() {
231: List returnTypes = new ArrayList();
232: returnTypes.add(RULE_ATTRIBUTE_ID_PROPERTY_NAME);
233: return returnTypes;
234: }
235:
236: public String getNoReturnParams(Map fieldConversions) {
237: String ruleIdReturn = (String) fieldConversions
238: .get(RULE_ATTRIBUTE_ID_PROPERTY_NAME);
239: StringBuffer noReturnParams = new StringBuffer("&");
240: if (!Utilities.isEmpty(ruleIdReturn)) {
241: noReturnParams.append(ruleIdReturn);
242: } else {
243: noReturnParams.append(RULE_ATTRIBUTE_ID_PROPERTY_NAME);
244: }
245: noReturnParams.append("=");
246: return noReturnParams.toString();
247: }
248:
249: /**
250: * @return Returns the instructions.
251: */
252: public String getLookupInstructions() {
253: return LOOKUP_INSTRUCTIONS;
254: }
255:
256: public String getTitle() {
257: return title;
258: }
259:
260: public String getReturnLocation() {
261: return returnLocation;
262: }
263:
264: public List getColumns() {
265: return columns;
266: }
267:
268: public String getHtmlMenuBar() {
269: return "";
270: }
271:
272: public List getRows() {
273: return rows;
274: }
275:
276: public ExportDataSet export(ExportFormat format,
277: Object exportCriteria) throws Exception {
278: List searchResults = (List) exportCriteria;
279: ExportDataSet dataSet = new ExportDataSet(format);
280: dataSet.getRuleAttributes().addAll(searchResults);
281: return dataSet;
282: }
283:
284: public List getSupportedExportFormats() {
285: return EdenConstants.STANDARD_FORMATS;
286: }
287:
288: }
|