001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.workflow.attribute;
017:
018: import java.util.ArrayList;
019: import java.util.HashMap;
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 org.apache.commons.lang.StringUtils;
027:
028: import edu.iu.uis.eden.EdenConstants;
029: import edu.iu.uis.eden.KEWServiceLocator;
030: import edu.iu.uis.eden.lookupable.Column;
031: import edu.iu.uis.eden.lookupable.Field;
032: import edu.iu.uis.eden.lookupable.Row;
033: import edu.iu.uis.eden.plugin.attributes.WorkflowAttribute;
034: import edu.iu.uis.eden.plugin.attributes.WorkflowLookupable;
035: import edu.iu.uis.eden.routetemplate.RuleBaseValues;
036: import edu.iu.uis.eden.routetemplate.RuleService;
037: import edu.iu.uis.eden.routetemplate.RuleTemplate;
038: import edu.iu.uis.eden.routetemplate.RuleTemplateService;
039: import edu.iu.uis.eden.util.KeyLabelPair;
040: import edu.iu.uis.eden.util.Utilities;
041:
042: /**
043: * This class provides a lookup for org review hierarchy routing rules.
044: */
045: public class OrgReviewLookupableImpl implements WorkflowLookupable {
046: private Long ruleTemplateId;
047: private WorkflowAttribute orgReviewAttribute;
048: private List rows;
049: private List columns;
050: private static final String ORG_REVIEW_TEMPLATE_NAME = "";
051: private static final String TITLE = "Org Review Lookup";
052: private static final String RETURN_LOCATION = "Lookup.do";
053: private static final String RULE_ID_FIELD_LABEL = "Rule Id";
054: private static final String DOC_TYP_NAME_FIELD_LABEL = "Document Type Name";
055: private static final String ACTIVE_IND_FIELD_LABEL = "Active Indicator";
056: private static final String RESPONSIBLE_PARTY_FIELD_LABEL = "Responsible Party";
057: private static final String RULE_ID_PROPERTY_NAME = "ruleId";
058: private static final String DOC_TYP_NAME_PROPERTY_NAME = "documentTypeName";
059: private static final String DOC_TYP_LOOKUPABLE = "DocumentTypeLookupableImplService";
060: private static final String ACTIVE_IND_PROPERTY_NAME = "activeIndicator";
061: private static final String RESPONSIBLE_PARTY_PROPERTY_NAME = "responsibleParty";
062: private static final String ALL_ACTIVE_INDICATOR_VALUE = "ALL";
063:
064: /**
065: * Constructs a OrgReviewLookupableImpl.java. Retrives the KualiOrgReviewTemplate from Spring, and initializes instance
066: * variables based on it.
067: */
068: public OrgReviewLookupableImpl() {
069: RuleTemplate ruleTemplate = ((RuleTemplateService) KEWServiceLocator
070: .getService(KEWServiceLocator.RULE_TEMPLATE_SERVICE))
071: .findByRuleTemplateName("KualiOrgReviewTemplate");
072: this .ruleTemplateId = ruleTemplate.getRuleTemplateId();
073: this .orgReviewAttribute = ruleTemplate
074: .getRuleTemplateAttribute(0).getWorkflowAttribute();
075: this .orgReviewAttribute.setRequired(false);
076: setRows();
077: setColumns();
078: }
079:
080: /**
081: * This method initializes the search criteria rows.
082: */
083: private void setRows() {
084: rows = new ArrayList();
085: List documentTypeFields = new ArrayList();
086: documentTypeFields.add(new Field(DOC_TYP_NAME_FIELD_LABEL, "",
087: Field.TEXT, true, DOC_TYP_NAME_PROPERTY_NAME, "", null,
088: DOC_TYP_LOOKUPABLE));
089: documentTypeFields.add(new Field("", "", Field.QUICKFINDER,
090: false, "", "", null, DOC_TYP_LOOKUPABLE));
091: rows.add(new Row(documentTypeFields));
092: List activeIndicatorOptions = new ArrayList();
093: activeIndicatorOptions.add(new KeyLabelPair(Boolean.TRUE
094: .toString(), "Active"));
095: activeIndicatorOptions.add(new KeyLabelPair(Boolean.FALSE
096: .toString(), "Inactive"));
097: activeIndicatorOptions.add(new KeyLabelPair(
098: ALL_ACTIVE_INDICATOR_VALUE, "Show All"));
099: List activeIndicatorFields = new ArrayList();
100: activeIndicatorFields.add(new Field(ACTIVE_IND_FIELD_LABEL, "",
101: Field.RADIO, false, ACTIVE_IND_PROPERTY_NAME,
102: Boolean.TRUE.toString(), activeIndicatorOptions, null));
103: rows.add(new Row(activeIndicatorFields));
104: rows.addAll(orgReviewAttribute.getRuleRows());
105: }
106:
107: /**
108: * This method initializes the result set columns.
109: */
110: private void setColumns() {
111: columns = new ArrayList();
112: columns.add(new Column(RULE_ID_FIELD_LABEL, Boolean.TRUE
113: .toString(), RULE_ID_PROPERTY_NAME));
114: columns.add(new Column(DOC_TYP_NAME_FIELD_LABEL, Boolean.TRUE
115: .toString(), DOC_TYP_NAME_PROPERTY_NAME));
116: columns.add(new Column(ACTIVE_IND_FIELD_LABEL, Boolean.TRUE
117: .toString(), ACTIVE_IND_PROPERTY_NAME));
118: Iterator extendedAttributeRowItr = orgReviewAttribute
119: .getRuleRows().iterator();
120: while (extendedAttributeRowItr.hasNext()) {
121: Row row = (Row) extendedAttributeRowItr.next();
122: Iterator fieldItr = row.getFields().iterator();
123: while (fieldItr.hasNext()) {
124: Field field = (Field) fieldItr.next();
125: if (Field.TEXT.equals(field.getFieldType())) {
126: columns.add(new Column(field.getFieldLabel(),
127: Boolean.TRUE.toString(), field
128: .getPropertyName()));
129: }
130: }
131:
132: }
133: columns.add(new Column(RESPONSIBLE_PARTY_FIELD_LABEL,
134: Boolean.TRUE.toString(),
135: RESPONSIBLE_PARTY_PROPERTY_NAME));
136: }
137:
138: /**
139: * This method uses edu.iu.uis.eden.routetemplate.RuleService#search(java.lang.String docTypeName, java.lang.Long ruleId,
140: * java.lang.Long ruleTemplateId, java.lang.String ruleDescription, java.lang.Long workgroupId, java.lang.String workflowId,
141: * java.lang.String roleName, java.lang.Boolean delegateRule, java.lang.Boolean activeInd, java.util.Map extensionValues) to
142: * retrieve a List of rules based on the search criteria specified, then converts the result set into OrgReviewLookupableResults
143: * and returns those.
144: *
145: * @see edu.iu.uis.eden.plugin.attributes.WorkflowLookupable#getSearchResults(java.util.Map, java.util.Map)
146: */
147: public List getSearchResults(Map fieldValues, Map fieldConversions)
148: throws Exception {
149: List errors = new ArrayList();
150: String docTypeNameParam = (String) fieldValues
151: .get(DOC_TYP_NAME_PROPERTY_NAME);
152: String activeParam = (String) fieldValues
153: .get(ACTIVE_IND_PROPERTY_NAME);
154: String docTypeSearchName = null;
155: Boolean isActive = null;
156: if (!activeParam.equals(ALL_ACTIVE_INDICATOR_VALUE)) {
157: isActive = new Boolean(activeParam);
158: }
159: if (docTypeNameParam != null
160: && !"".equals(docTypeNameParam.trim())) {
161: docTypeSearchName = docTypeNameParam.replace('*', '%');
162: docTypeSearchName = "%" + docTypeSearchName.trim() + "%";
163: }
164: Map attributes = new HashMap();
165: Iterator attributeRowItr = orgReviewAttribute.getRuleRows()
166: .iterator();
167: while (attributeRowItr.hasNext()) {
168: Row attributeRow = (Row) attributeRowItr.next();
169: Iterator attributeFieldItr = attributeRow.getFields()
170: .iterator();
171: while (attributeFieldItr.hasNext()) {
172: Field attributeField = (Field) attributeFieldItr.next();
173: if (fieldValues.get(attributeField.getPropertyName()) != null) {
174: String attributeValue = (String) fieldValues
175: .get(attributeField.getPropertyName());
176: if (!StringUtils.isBlank(attributeValue)) {
177: attributes.put(
178: attributeField.getPropertyName(),
179: attributeValue.trim());
180: }
181: }
182: }
183: }
184: Iterator rules = ((RuleService) KEWServiceLocator
185: .getService(KEWServiceLocator.RULE_SERVICE)).search(
186: docTypeSearchName, null, ruleTemplateId, null, null,
187: null, null, null, isActive, attributes).iterator();
188: List displayList = new ArrayList();
189: while (rules.hasNext()) {
190: displayList.add(new OrgReviewLookupableResult(
191: (RuleBaseValues) rules.next()));
192: }
193: return displayList;
194: }
195:
196: /**
197: * @see edu.iu.uis.eden.EdenConstants.RULE_SEARCH_INSTRUCTION_KEY
198: * @see edu.iu.uis.eden.plugin.attributes.WorkflowLookupable#getLookupInstructions()
199: */
200: public String getLookupInstructions() {
201: return Utilities
202: .getApplicationConstant(EdenConstants.RULE_SEARCH_INSTRUCTION_KEY);
203: }
204:
205: /**
206: * @see edu.iu.uis.eden.plugin.attributes.WorkflowLookupable#getTitle()
207: */
208: public String getTitle() {
209: return TITLE;
210: }
211:
212: /**
213: * Since this is a lookup, we return Lookup.do.
214: *
215: * @see edu.iu.uis.eden.plugin.attributes.WorkflowLookupable#getReturnLocation()
216: */
217: public String getReturnLocation() {
218: return RETURN_LOCATION;
219: }
220:
221: /**
222: * Returns unodified instance variable initialized in setColumns(), called from the constructor.
223: *
224: * @see edu.iu.uis.eden.plugin.attributes.WorkflowLookupable#getColumns()
225: */
226: public List getColumns() {
227: return columns;
228: }
229:
230: /**
231: * Returns unmodified instance variable initialized in setRows(), called from the constructor.
232: *
233: * @see edu.iu.uis.eden.plugin.attributes.WorkflowLookupable#getRows()
234: */
235: public List getRows() {
236: return rows;
237: }
238:
239: /**
240: * Returns the empty String.
241: *
242: * @see edu.iu.uis.eden.plugin.attributes.WorkflowLookupable#getHtmlMenuBar()
243: */
244: public String getHtmlMenuBar() {
245: return "";
246: }
247:
248: /**
249: * Returns the empty String.
250: *
251: * @see edu.iu.uis.eden.plugin.attributes.WorkflowLookupable#getNoReturnParams(java.util.Map)
252: */
253: public String getNoReturnParams(Map fieldConversions) {
254: return "";
255: }
256:
257: /**
258: * Returns an empty List.
259: *
260: * @see edu.iu.uis.eden.plugin.attributes.WorkflowLookupable#getDefaultReturnType()
261: */
262: public List getDefaultReturnType() {
263: return new ArrayList();
264: }
265:
266: /**
267: * Does nothing and returns false.
268: *
269: * @see edu.iu.uis.eden.plugin.attributes.WorkflowLookupable#checkForAdditionalFields(java.util.Map,
270: * javax.servlet.http.HttpServletRequest)
271: */
272: public boolean checkForAdditionalFields(Map fieldValues,
273: HttpServletRequest request) throws Exception {
274: return false;
275: }
276:
277: /**
278: * Does nothing.
279: *
280: * @see edu.iu.uis.eden.plugin.attributes.WorkflowLookupable#changeIdToName(java.util.Map)
281: */
282: public void changeIdToName(Map fieldValues) {
283: }
284: }
|