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.doctype.web;
018:
019: import java.util.List;
020:
021: import javax.servlet.http.HttpServletRequest;
022: import javax.servlet.http.HttpServletResponse;
023:
024: import org.apache.struts.action.ActionForm;
025: import org.apache.struts.action.ActionForward;
026: import org.apache.struts.action.ActionMapping;
027: import org.apache.struts.action.ActionMessages;
028:
029: import edu.iu.uis.eden.KEWServiceLocator;
030: import edu.iu.uis.eden.clientapp.WorkflowDocument;
031: import edu.iu.uis.eden.clientapp.vo.WorkflowIdVO;
032: import edu.iu.uis.eden.doctype.DocumentType;
033: import edu.iu.uis.eden.doctype.DocumentTypeService;
034: import edu.iu.uis.eden.export.ExportDataSet;
035: import edu.iu.uis.eden.export.ExportFormat;
036: import edu.iu.uis.eden.services.ServiceConstants;
037: import edu.iu.uis.eden.web.WorkflowAction;
038: import edu.iu.uis.eden.workgroup.GroupNameId;
039: import edu.iu.uis.eden.workgroup.WorkgroupService;
040:
041: /**
042: * Action for doing document type stuff from the web. This is exists for reporting purposes
043: * only at this point.
044: *
045: * @author rkirkend
046: * @author ewestfal
047: */
048: public class DocumentTypeAction extends WorkflowAction {
049: private static String DOCUMENT_TYPE = "EDENSERVICE-DOCS.DocumentType";
050:
051: public ActionForward start(ActionMapping mapping, ActionForm form,
052: HttpServletRequest request, HttpServletResponse response)
053: throws Exception {
054: DocumentTypeForm documentTypeForm = (DocumentTypeForm) form;
055: // setRouteLevelToException(documentTypeForm.getRouteLevel());
056: documentTypeForm.getDocumentType().setActiveInd(
057: new Boolean(true));
058: documentTypeForm.setDocTypeVisible(true);
059: documentTypeForm.setPolicyVisible(true);
060: documentTypeForm.setRouteLevelVisible(true);
061: documentTypeForm.setSearchableAttributeVisible(true);
062: documentTypeForm.setNewRouteModuleVisible("no");
063: documentTypeForm.setDefaultApprove("true");
064: documentTypeForm.setPreApprove("true");
065: documentTypeForm.setInitiatorMustRoute("true");
066: documentTypeForm.setInitiatorMustSave("true");
067: return mapping.findForward("basic");
068: }
069:
070: public ActionMessages establishRequiredState(
071: HttpServletRequest request, ActionForm form)
072: throws Exception {
073: DocumentTypeForm documentTypeForm = (DocumentTypeForm) form;
074:
075: if (getWorkgroupService()
076: .isUserMemberOfGroup(
077: new GroupNameId(
078: ServiceConstants.DOC_TYPE_BLANKET_APPRV_WRKGRP),
079: getUserSession(request).getWorkflowUser())) {
080: documentTypeForm.setShowBlanketApproveButton(true);
081: }
082:
083: if (documentTypeForm.getDocumentType().getDocumentTypeId() != null
084: && documentTypeForm.getDocumentType()
085: .getDocumentTypeId().longValue() != 0) {
086: DocumentType existing = getDocumentTypeService().findById(
087: documentTypeForm.getDocumentType()
088: .getDocumentTypeId());
089: // Workgroup workgroup = getWorkgroupService().getWorkgroup(new WorkflowGroupId(existing.getWorkgroupId()));
090: // if (workgroup != null) {
091: // existing.setWorkgroupId(workgroup.getWorkflowGroupId().getGroupId());
092: // }
093: // if (existing.getBlanketApproveWorkgroupId() != null) {
094: // Workgroup blanketApproveWorkgroup = getWorkgroupService().getWorkgroup(new WorkflowGroupId(existing.getBlanketApproveWorkgroupId()));
095: // if (blanketApproveWorkgroup != null) {
096: // existing.setBlanketApproveWorkgroupId(blanketApproveWorkgroup.getWorkflowGroupId().getGroupId());
097: // }
098: // }
099: // if (existing.getParentDocType() != null) {
100: // existing.setCustomActionListAttributeClassName(existing
101: // .retrieveAttributeClassName(existing.getCustomActionListAttributeClassName(), EdenConstants.ACTION_LIST_ATTRIBUTE_CLASS_PROPERTY));
102: // existing.setCustomEmailAttributeClassName(existing.retrieveAttributeClassName(existing.getCustomEmailAttributeClassName(), EdenConstants.EMAIL_ATTRIBUTE_CLASS_PROPERTY));
103: // existing.setCustomNoteAttributeClassName(existing.retrieveAttributeClassName(existing.getCustomNoteAttributeClassName(), EdenConstants.NOTE_ATTRIBUTE_CLASS_PROPERTY));
104: // }
105: documentTypeForm.setExistingDocumentType(existing);
106: }
107: String parentDocTypeName = documentTypeForm
108: .getParentDocTypeName();
109: if (parentDocTypeName != null
110: && !"".equals(parentDocTypeName.trim())) {
111: documentTypeForm.getDocumentType().setDocTypeParentId(
112: getDocumentTypeService().findByName(
113: parentDocTypeName).getDocumentTypeId());
114: // if (documentTypeForm.getDocumentType().getParentDocType() != null) {
115: // documentTypeForm.getDocumentType().setCustomActionListAttributeClassName(
116: // documentTypeForm.getDocumentType().retrieveAttributeClassName(documentTypeForm.getDocumentType().getCustomActionListAttributeClassName(),
117: // EdenConstants.ACTION_LIST_ATTRIBUTE_CLASS_PROPERTY));
118: // documentTypeForm.getDocumentType().setCustomEmailAttributeClassName(
119: // documentTypeForm.getDocumentType().retrieveAttributeClassName(documentTypeForm.getDocumentType().getCustomEmailAttributeClassName(),
120: // EdenConstants.EMAIL_ATTRIBUTE_CLASS_PROPERTY));
121: // documentTypeForm.getDocumentType().setCustomNoteAttributeClassName(
122: // documentTypeForm.getDocumentType()
123: // .retrieveAttributeClassName(documentTypeForm.getDocumentType().getCustomNoteAttributeClassName(), EdenConstants.NOTE_ATTRIBUTE_CLASS_PROPERTY));
124: // }
125: }
126:
127: // this code sucks and needs reworked RK
128: if (documentTypeForm.getDocId() != null) { // I'm for the dochandler
129: documentTypeForm.setFlexDoc(new WorkflowDocument(
130: new WorkflowIdVO(getUserSession(request)
131: .getWorkflowUser().getWorkflowId()),
132: documentTypeForm.getDocId()));
133: documentTypeForm.establishVisibleActionRequestCds();
134: } else if (documentTypeForm.getDocTypeId() != null) { // I'm for the
135: // report
136: // do nothing I'm doing work in report method
137: } else { // I'm for editing and creating new
138: documentTypeForm.setFlexDoc(new WorkflowDocument(
139: new WorkflowIdVO(getUserSession(request)
140: .getWorkflowUser().getWorkflowId()),
141: DOCUMENT_TYPE));
142: documentTypeForm.setDocId(documentTypeForm.getFlexDoc()
143: .getRouteHeaderId());
144: documentTypeForm.establishVisibleActionRequestCds();
145: }
146: // seems like work could all be done on the generic docId to clear up
147: // this mess
148: return null;
149: }
150:
151: public ActionMessages establishFinalState(
152: HttpServletRequest request, ActionForm form)
153: throws Exception {
154: return null;
155: }
156:
157: public ActionForward report(ActionMapping mapping, ActionForm form,
158: HttpServletRequest request, HttpServletResponse response)
159: throws Exception {
160: DocumentTypeForm documentTypeForm = (DocumentTypeForm) form;
161: DocumentType docType = getDocumentTypeService().findById(
162: new Long(request.getParameter("docTypeId")));
163:
164: if (docType.getRouteHeaderId() != null
165: && docType.getRouteHeaderId().longValue() != 0) {
166: documentTypeForm.setFlexDoc(new WorkflowDocument(
167: new WorkflowIdVO(getUserSession(request)
168: .getWorkflowUser().getWorkflowId()),
169: docType.getRouteHeaderId()));
170: }
171: documentTypeForm.establishVisibleActionRequestCds();
172:
173: documentTypeForm.setDocumentType(docType);
174:
175: ExportDataSet dataSet = new ExportDataSet(ExportFormat.XML);
176: dataSet.getDocumentTypes().add(docType);
177: byte[] data = KEWServiceLocator.getXmlExporterService().export(
178: dataSet.getFormat(), dataSet);
179: documentTypeForm.setExportedXml(new String(data));
180:
181: return mapping.findForward("report");
182: }
183:
184: public ActionForward export(ActionMapping mapping, ActionForm form,
185: HttpServletRequest request, HttpServletResponse response)
186: throws Exception {
187: DocumentType docType = getDocumentTypeService().findById(
188: new Long(request.getParameter("docTypeId")));
189: ExportDataSet dataSet = new ExportDataSet(ExportFormat.XML);
190: dataSet.getDocumentTypes().add(docType);
191: return exportDataSet(request, dataSet);
192: }
193:
194: public ActionForward exportHierarchy(ActionMapping mapping,
195: ActionForm form, HttpServletRequest request,
196: HttpServletResponse response) throws Exception {
197: DocumentType docType = getDocumentTypeService().findById(
198: new Long(request.getParameter("docTypeId")));
199: ExportDataSet dataSet = new ExportDataSet(ExportFormat.XML);
200: List docTypes = dataSet.getDocumentTypes();
201: do {
202: docTypes.add(docType);
203: docType = docType.getParentDocType();
204: } while (docType != null);
205: return exportDataSet(request, dataSet);
206: }
207:
208: private DocumentTypeService getDocumentTypeService() {
209: return (DocumentTypeService) KEWServiceLocator
210: .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE);
211: }
212:
213: private WorkgroupService getWorkgroupService() {
214: return (WorkgroupService) KEWServiceLocator
215: .getService(KEWServiceLocator.WORKGROUP_SRV);
216: }
217:
218: }
|