001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.console.web.admin;
009:
010: //base classes
011: import java.io.IOException;
012:
013: //project specific classes
014: import org.jfolder.common.UnexpectedSystemException;
015: import org.jfolder.common.utils.misc.MiscHelper;
016: import org.jfolder.common.utils.web.ParameterSet;
017: import org.jfolder.common.web.template.ConsoleParameterContext;
018: import org.jfolder.common.web.template.SubmitActionContext;
019: import org.jfolder.common.web.template.SubmitActionParameters;
020: import org.jfolder.console.base.BaseConsoleServlet;
021: import org.jfolder.console.base.ConsolePageContext;
022: import org.jfolder.console.base.ConsolePageMessageHolder;
023: import org.jfolder.console.base.ConsolePageSession;
024: import org.jfolder.security.audit.SecurityAudit;
025: import org.jfolder.security.lifecycle.SecurityLifecycle;
026: import org.jfolder.security.lifecycle.SecurityLifecycleHelper;
027: import org.jfolder.security.model.UserHolder;
028: import org.jfolder.workflow.model.WorkflowComponentIdentifyUpdatesContext;
029: import org.jfolder.workflow.model.dms.WorkflowDocumentGroup;
030: import org.jfolder.workflow.model.dms.WorkflowDocumentSet;
031: import org.jfolder.workflow.model.instance.WorkflowInstance;
032: import org.jfolder.workflow.model.instance.WorkflowInstanceUpdates;
033: import org.jfolder.workflow.model.trigger.WorkflowTrigger;
034:
035: //other classes
036:
037: public class AdminManualTriggerServlet extends BaseConsoleServlet {
038:
039: public AdminManualTriggerServlet() {
040: }
041:
042: protected boolean checkAccess(ConsolePageSession inCps) {
043:
044: boolean outValue = false;
045:
046: outValue = inCps.isAdministrator();
047:
048: return outValue;
049: }
050:
051: public ConsolePageContext process(ConsolePageSession inCps,
052: UserHolder inUser, ParameterSet inPs,
053: SubmitActionContext inSac) throws IOException {
054:
055: ConsolePageContext outValue = null;
056:
057: if (inSac.isAction(SubmitActionParameters.OPEN)) {
058: if (inCps.getWorkflowInstance() == null) {
059:
060: //
061: WorkflowInstance wi = WorkflowInstance.newInstance();
062:
063: //
064: WorkflowTrigger wt = WorkflowTrigger.newInstance();
065: wt.setDataAsString("<trigger></trigger>");
066:
067: //
068: WorkflowDocumentSet wds = WorkflowDocumentSet
069: .newInstance();
070:
071: //
072: wi.setWorkflowTrigger(wt);
073: wi.setWorkflowDocumentSet(wds);
074:
075: //
076: inCps.setWorkflowInstance(wi);
077: }
078: //MiscHelper.println("Open action executed");
079: } else {
080: //
081: WorkflowInstance wi = inCps.getWorkflowInstance();
082: //
083: WorkflowTrigger td = wi.getWorkflowTrigger();
084: updateTrigger(td, inSac);
085: //
086: WorkflowDocumentSet wds = wi.getWorkflowDocumentSet();
087: //
088: if (inSac.isAction(SubmitActionParameters.ADD,
089: SubmitActionParameters.DOCUMENT,
090: SubmitActionParameters.GROUP)) {
091: //
092: String dgName = inSac
093: .getParameter(ConsoleParameterContext.FIRST_INPUT);
094: WorkflowDocumentGroup dg = WorkflowDocumentGroup
095: .newInstance(dgName);
096: dg.setDeletable(true);
097: wds.addDocumentGroup(dg);
098: } else if (inSac
099: .isAction(SubmitActionParameters.DO_NOTHING)) {
100: } else if (inSac.isAction(SubmitActionParameters.DELETE,
101: SubmitActionParameters.DOCUMENT,
102: SubmitActionParameters.GROUP)) {
103: //
104: wds
105: .removeDocumentGroup(inSac
106: .getParameter(ConsoleParameterContext.FIRST_INPUT));
107: } else if (inSac.isAction(SubmitActionParameters.ADD,
108: SubmitActionParameters.DOCUMENT,
109: SubmitActionParameters.INSTANCE)) {
110: //
111: String dgName = inSac
112: .getParameter(ConsoleParameterContext.FIRST_INPUT);
113: WorkflowDocumentGroup dg = wds.getDocumentGroup(dgName);
114: //
115: String uploadFile = inSac
116: .getParameter(ConsoleParameterContext.SECOND_INPUT);
117: byte fileContent[] = inPs
118: .getParameterAsUpload(uploadFile);
119: String fileName = inPs
120: .getUploadParameterName(uploadFile);
121: dg.addDocument(fileName, fileContent);
122: } else if (inSac.isAction(SubmitActionParameters.DELETE,
123: SubmitActionParameters.DOCUMENT,
124: SubmitActionParameters.INSTANCE)) {
125: //
126: String dgName = inSac
127: .getParameter(ConsoleParameterContext.FIRST_INPUT);
128: WorkflowDocumentGroup dg = wds.getDocumentGroup(dgName);
129: //
130: dg
131: .removeDocument(inSac
132: .getParameter(ConsoleParameterContext.SECOND_INPUT));
133: } else if (inSac
134: .isAction(SubmitActionParameters.FIRE_TRIGGER)) {
135:
136: //WorkflowLifecycle wl =
137: // WorkflowLifecycleFactory.getWorkflowLifecycle();
138:
139: //MiscHelper.println("trigger = " + inSac.getFirstParameter());
140: //MiscHelper.println("app = " + inSac.getSecondParameter());
141: //
142: //
143: //
144: //SecurityAudit sa = SecurityAudit.newInstance(inUser,
145: // SecurityAudit.INITIAL_ID, "Console Trigger Submission",
146: // WorkflowTrigger.SUBMITTED, MiscHelper.currentGMT());
147: ////TriggerData td = TriggerData.newInstance();
148: //
149: ////WorkflowInstance wi = new WorkflowInstance();
150: ////wi.setWorkflowTrigger(td);
151: //
152: //WorkflowComponentIdentifyUpdatesContext wciuc =
153: // WorkflowComponentIdentifyUpdatesContext.newInstance(sa);
154: //
155: //WorkflowInstanceUpdates wiu =
156: // (WorkflowInstanceUpdates)wi.identifyUpdates(wciuc);
157: ////wl.submitTriggerData(null, td);
158: //wl.updateWorkflowInstance(wiu);
159: //
160: //
161: //
162: //wl.close();
163: //throw UnexpectedSystemException.notImplemented();
164: } else if (inSac.isAction(SubmitActionParameters.UPDATE,
165: SubmitActionParameters.PROPERTY)) {
166:
167: String appName = inSac
168: .getParameter(ConsoleParameterContext.FIRST_INPUT);
169: String propName = inSac
170: .getParameter(ConsoleParameterContext.SECOND_INPUT);
171: String propValue = inSac
172: .getParameter(ConsoleParameterContext.THIRD_INPUT);
173: //
174: if (!td.isPropertyPresent(propName)) {
175: ConsolePageMessageHolder nextCpmh = inCs
176: .getMessageHolder().createSubMessage();
177: nextCpmh
178: .setErrorHeader("Action Cancelled: property '"
179: + propName + "' does not exist");
180: } else {
181: td.updateProperty(propName, propValue);
182: }
183: } else if (inSac.isAction(SubmitActionParameters.DELETE,
184: SubmitActionParameters.PROPERTY)) {
185:
186: String appName = inSac
187: .getParameter(ConsoleParameterContext.FIRST_INPUT);
188: String propName = inSac
189: .getParameter(ConsoleParameterContext.SECOND_INPUT);
190: //
191: if (!td.isPropertyPresent(propName)) {
192: ConsolePageMessageHolder nextCpmh = inCs
193: .getMessageHolder().createSubMessage();
194: nextCpmh
195: .setErrorHeader("Action Cancelled: property '"
196: + propName + "' does not exist");
197: } else {
198: td.removeProperty(propName);
199: }
200: } else if (inSac.isAction(SubmitActionParameters.CREATE,
201: SubmitActionParameters.PROPERTY)) {
202:
203: String appName = inSac
204: .getParameter(ConsoleParameterContext.FIRST_INPUT);
205: String propName = inSac
206: .getParameter(ConsoleParameterContext.SECOND_INPUT);
207: String propValue = inSac
208: .getParameter(ConsoleParameterContext.THIRD_INPUT);
209: //
210: if (td.isPropertyPresent(propName)) {
211: ConsolePageMessageHolder nextCpmh = inCs
212: .getMessageHolder().createSubMessage();
213: nextCpmh
214: .setErrorHeader("Action Cancelled: property '"
215: + propName + "' already exist");
216: } else {
217: td.addProperty(propName, propValue);
218: }
219: } else {
220: inSac.unknownAction();
221: }
222: }
223:
224: outValue = AdminManualTriggerContext.newInstance(inCps);
225:
226: return outValue;
227: }
228:
229: private void updateTrigger(WorkflowTrigger inTd,
230: SubmitActionContext inSac) {
231: inTd.setDataAsString(inSac.getParameter(inSac.NINTH_INPUT));
232: }
233: }
|