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.edl.EDocLiteAssociation;
029: import edu.iu.uis.eden.edl.EDocLiteService;
030: import edu.iu.uis.eden.edl.components.WorkflowDocumentActions;
031: import edu.iu.uis.eden.export.ExportDataSet;
032: import edu.iu.uis.eden.export.ExportFormat;
033: import edu.iu.uis.eden.export.Exportable;
034: import edu.iu.uis.eden.plugin.attributes.WorkflowLookupable;
035: import edu.iu.uis.eden.util.KeyLabelPair;
036: import edu.iu.uis.eden.util.Utilities;
037:
038: /**
039: * A {@link WorkflowLookupable} for EDoc Lites.
040: *
041: * @see EDocLiteService
042: *
043: * @author rkirkend
044: */
045: public class EDocLiteLookupable implements WorkflowLookupable,
046: Exportable {
047:
048: private List ROWS;
049: private static final List COLUMNS = establishColData();
050:
051: private static final String EDOC_LITE_NAME = "eDocLiteName_";
052: private static final String EDOC_LITE_STYLE_NAME = "eDocLiteStyleName_";
053: private static final String EDOC_LITE_DOC_TYPE_NAME = "eDocLiteDocName_";
054: private static final String ACTIVE_IND_FIELD_LABEL = "Active Indicator";
055: private static final String ACTIVE_IND_PROPERTY_NAME = "activeIndicator";
056:
057: public EDocLiteLookupable() {
058: this .ROWS = establishRowData();
059: }
060:
061: public String getHtmlMenuBar() {
062: return "";
063: }
064:
065: public List getRows() {
066: return ROWS;
067: }
068:
069: public String getTitle() {
070: return "EDocLite Lookup";
071: }
072:
073: public String getReturnLocation() {
074: return "Lookup.do";
075: }
076:
077: public List getColumns() {
078: return COLUMNS;
079: }
080:
081: public List getSearchResults(Map fieldValues, Map fieldConversions)
082: throws Exception {
083: EDocLiteAssociation edocLite = new EDocLiteAssociation();
084:
085: String activeInd = (String) fieldValues
086: .get(ACTIVE_IND_PROPERTY_NAME);
087: if (!Utilities.isEmpty(activeInd) && !activeInd.equals("all")) {
088: edocLite.setActiveInd(new Boolean(activeInd.trim()));
089: }
090: String definition = (String) fieldValues.get(EDOC_LITE_NAME);
091: if (!Utilities.isEmpty(definition)) {
092: edocLite.setDefinition(definition.trim());
093: }
094: String style = (String) fieldValues.get(EDOC_LITE_STYLE_NAME);
095: if (!Utilities.isEmpty(style)) {
096: edocLite.setStyle(style.trim());
097: }
098: String documentType = (String) fieldValues
099: .get(EDOC_LITE_DOC_TYPE_NAME);
100: if (!Utilities.isEmpty(documentType)) {
101: edocLite.setEdlName(documentType.trim());
102: }
103: List results = KEWServiceLocator.getEDocLiteService().search(
104: edocLite);
105: for (Iterator iter = results.iterator(); iter.hasNext();) {
106: EDocLiteAssociation result = (EDocLiteAssociation) iter
107: .next();
108: String actionsUrl = "<a href=\"EDocLite?userAction="
109: + WorkflowDocumentActions.ACTION_CREATE
110: + "&edlName=" + result.getEdlName()
111: + "\">Create Document</a>";
112: result.setActionsUrl(actionsUrl);
113: }
114: return results;
115: }
116:
117: public String getNoReturnParams(Map fieldConversions) {
118: return null;
119: }
120:
121: public String getLookupInstructions() {
122: return "EDocLite Lookup";
123: }
124:
125: public List getDefaultReturnType() {
126: List returnTypes = new ArrayList();
127: returnTypes.add(EDOC_LITE_NAME);
128: return returnTypes;
129: }
130:
131: public boolean checkForAdditionalFields(Map fieldValues,
132: HttpServletRequest request) throws Exception {
133: return false;
134: }
135:
136: public void changeIdToName(Map fieldValues) throws Exception {
137: }
138:
139: public ExportDataSet export(ExportFormat format,
140: Object exportCriteria) throws Exception {
141: List searchResults = (List) exportCriteria;
142: ExportDataSet dataSet = new ExportDataSet(format);
143: dataSet.getEdocLites().addAll(searchResults);
144: return dataSet;
145: }
146:
147: public List getSupportedExportFormats() {
148: return EdenConstants.STANDARD_FORMATS;
149: }
150:
151: private static List establishColData() {
152: List cols = new ArrayList();
153: cols.add(new Column("Definition Name",
154: Column.COLUMN_IS_SORTABLE_VALUE, "definition"));
155: cols.add(new Column("Style Name",
156: Column.COLUMN_IS_SORTABLE_VALUE, "style"));
157: cols.add(new Column("DocumentType Name",
158: Column.COLUMN_IS_SORTABLE_VALUE, "edlName"));
159: cols.add(new Column("Active Indicator",
160: Column.COLUMN_IS_SORTABLE_VALUE, "activeInd"));
161: cols.add(new Column("Action", Column.COLUMN_NOT_SORTABLE_VALUE,
162: "actionsUrl"));
163: return cols;
164: }
165:
166: private List establishRowData() {
167: List rows = new ArrayList();
168: List fields = new ArrayList();
169: fields.add(new Field("Definition Name", "", Field.TEXT, false,
170: EDOC_LITE_NAME, "", null, "", null));
171: rows.add(new Row(fields));
172:
173: fields = new ArrayList();
174: fields.add(new Field("Style Name", "", Field.TEXT, false,
175: EDOC_LITE_STYLE_NAME, "", null, "", null));
176: rows.add(new Row(fields));
177:
178: fields = new ArrayList();
179: fields.add(new Field("Document Type Name", "", Field.TEXT,
180: false, EDOC_LITE_DOC_TYPE_NAME, "", null, "", null));
181: rows.add(new Row(fields));
182:
183: List options = new ArrayList();
184: options.add(new KeyLabelPair("true", "Active"));
185: options.add(new KeyLabelPair("false", "Inactive"));
186: options.add(new KeyLabelPair("all", "Show All"));
187:
188: fields = new ArrayList();
189: fields
190: .add(new Field(ACTIVE_IND_FIELD_LABEL, "", Field.RADIO,
191: false, ACTIVE_IND_PROPERTY_NAME, "true",
192: options, null));
193: rows.add(new Row(fields));
194: return rows;
195: }
196:
197: }
|