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.workflow.model.trigger;
009:
010: //base classes
011: import java.util.ArrayList;
012: import java.util.HashMap;
013: import java.util.Iterator;
014:
015: //project specific classes
016: import org.jfolder.common.UnexpectedSystemException;
017: import org.jfolder.security.audit.SecurityAudit;
018: import org.jfolder.workflow.model.WorkflowComponent;
019: import org.jfolder.workflow.model.WorkflowComponentApplyUpdatesContext;
020: import org.jfolder.workflow.model.WorkflowComponentIdentifyUpdatesContext;
021: import org.jfolder.workflow.model.WorkflowComponentUpdates;
022: import org.jfolder.workflow.model.dms.WorkflowDocumentGroup;
023:
024: //other classes
025:
026: public class WorkflowTrigger extends WorkflowComponent {
027:
028: public final static String SUBMITTED = "SUBMITTED";
029: public final static String PROCESSED = "PROCESSED";
030: public final static String RETIRED = "RETIRED";
031:
032: private String data = null;
033: private String originalData = null;
034: //private boolean previousTriggerPresent = false;
035: //private TriggerData previousTrigger = null;
036: //private String workflowId = null;
037: //
038: private HashMap propertiesMap = null;
039: private ArrayList propertiesArray = null;
040: private HashMap originalPropertiesMap = null;
041:
042: //
043:
044: //private TriggerDataBean(String inData, boolean inPreviousTriggerPresent,
045: // TriggerData inPreviousTrigger, WorkflowAudit inWa) {
046: //
047: // super(inWa);
048: //
049: // this.data = inData;
050: // this.previousTriggerPresent = inPreviousTriggerPresent;
051: // this.previousTrigger = inPreviousTrigger;
052: //}
053:
054: protected WorkflowTrigger() {
055:
056: super ();
057: //
058: this .propertiesMap = new HashMap();
059: this .propertiesArray = new ArrayList();
060: this .originalPropertiesMap = new HashMap();
061: //
062: //this.data = inData;
063: //this.workflowId = inWorkflowId;
064: }
065:
066: public final static WorkflowTrigger newInstance() {
067:
068: return new WorkflowTrigger();
069: }
070:
071: //protected TriggerDataBean(String inData, TriggerData inPreviousTrigger,
072: // WorkflowAudit inWa) {
073: //
074: // this(inData, true, inPreviousTrigger, inWa);
075: //}
076:
077: public String getDataAsString() {
078: return this .data;
079: }
080:
081: public void setDataAsString(String inData) {
082: this .data = inData;
083: }
084:
085: //public boolean isPreviousTriggerPresent() {
086: // return this.previousTriggerPresent;
087: //}
088:
089: //public TriggerData getPreviousTrigger() {
090: // return this.previousTrigger;
091: //}
092:
093: //public String getWorkflowId() {
094: // return this.workflowId;
095: //}
096: //
097: //public void setWorkflowId(String inWorkflowId) {
098: // this.workflowId = inWorkflowId;
099: //}
100:
101: //public void setAuditStatus(String inStatus) {
102: // super.setAuditStatus(inStatus);
103: //}
104:
105: public String getProperty(String inName) {
106:
107: String outValue = null;
108:
109: if (this .propertiesMap.containsKey(inName)) {
110: outValue = (String) this .propertiesMap.get(inName);
111: } else {
112: throw new UnexpectedSystemException("Property '" + inName
113: + "' does not exist");
114: }
115:
116: return outValue;
117: }
118:
119: public String getPropertyName(int inIndex) {
120:
121: String outValue = null;
122:
123: outValue = (String) this .propertiesArray.get(inIndex);
124:
125: return outValue;
126: }
127:
128: public String getProperty(int inIndex) {
129:
130: String outValue = null;
131:
132: String propName = (String) this .propertiesArray.get(inIndex);
133: outValue = (String) this .propertiesMap.get(propName);
134:
135: return outValue;
136: }
137:
138: public int getPropertyCount() {
139: return this .propertiesArray.size();
140: }
141:
142: public boolean isPropertyPresent(String inName) {
143: return this .propertiesMap.containsKey(inName);
144: }
145:
146: public void addProperty(String inName, String inValue) {
147: if (!this .propertiesMap.containsKey(inName)) {
148: this .propertiesMap.put(inName, inValue);
149: this .propertiesArray.add(inName);
150: } else {
151: throw new UnexpectedSystemException("Property '" + inName
152: + "' already exists");
153: }
154: }
155:
156: public void updateProperty(String inName, String inValue) {
157: if (this .propertiesMap.containsKey(inName)) {
158: this .propertiesMap.put(inName, inValue);
159: } else {
160: throw new UnexpectedSystemException("Property '" + inName
161: + "' does not exists");
162: }
163: }
164:
165: public void removeProperty(String inName) {
166: if (this .propertiesMap.containsKey(inName)) {
167: this .propertiesMap.remove(inName);
168: this .propertiesArray.remove(inName);
169: } else {
170: throw new UnexpectedSystemException("Property '" + inName
171: + "' does not exists");
172: }
173: }
174:
175: public WorkflowComponentUpdates identifyUpdates(
176: WorkflowComponentIdentifyUpdatesContext inWciuc) {
177:
178: WorkflowTriggerUpdates outValue = new WorkflowTriggerUpdates();
179:
180: //
181: //PROPERTIES
182: //
183: ArrayList propCommands = new ArrayList();
184: ArrayList propNames = new ArrayList();
185: ArrayList propValues = new ArrayList();
186: //
187: HashMap removePropMap = (HashMap) this .originalPropertiesMap
188: .clone();
189: //
190: Iterator addUpdatePropIter = this .propertiesMap.keySet()
191: .iterator();
192: while (addUpdatePropIter.hasNext()) {
193: String nextPropName = (String) addUpdatePropIter.next();
194: String nextPropValue = (String) this .propertiesMap
195: .get(nextPropName);
196: if (!(removePropMap.containsKey(nextPropName))) {
197: propCommands.add(WorkflowTriggerUpdates.ADD);
198: propNames.add(nextPropName);
199: propValues.add(nextPropValue);
200: } else {
201: String origPropValue = (String) removePropMap
202: .get(nextPropName);
203: removePropMap.remove(nextPropName);
204: if (!(origPropValue.equals(nextPropValue))) {
205: propCommands.add(WorkflowTriggerUpdates.UPDATE);
206: propNames.add(nextPropName);
207: propValues.add(nextPropValue);
208: } else {
209: //values the same, no change necessary
210: }
211: }
212: }
213: //
214: Iterator removePropIter = removePropMap.keySet().iterator();
215: while (removePropIter.hasNext()) {
216: String nextPropName = (String) removePropIter.next();
217: String nextPropValue = (String) removePropMap
218: .get(nextPropName);
219: //
220: propCommands.add(WorkflowTriggerUpdates.REMOVE);
221: propNames.add(nextPropName);
222: propValues.add(nextPropValue);
223: }
224: //
225: outValue
226: .setPropertyUpdates(propCommands, propNames, propValues);
227: //
228: //DATA
229: //
230: String updateData = null;
231: if (this .data != null) {
232: if ((this .originalData) == null
233: || (this .data.equals(this .originalData))) {
234: updateData = this .data;
235: }
236: } else {
237: throw new UnexpectedSystemException("Trigger data not set");
238: }
239:
240: //
241: //RESET
242: //
243: //this.refreshSecurityAudit(inSa);
244: this .originalPropertiesMap = (HashMap) this .propertiesMap
245: .clone();
246: //
247: this .originalData = this .data;
248: //this.annotations = new ArrayList();
249:
250: return outValue;
251: }
252:
253: //public WorkflowComponentUpdates identifyUpdates(
254: // WorkflowComponentIdentifyUpdatesContext inWciuc) {
255: // throw UnexpectedSystemException.notImplemented();
256: //}
257:
258: public void applyUpdates(
259: WorkflowComponentApplyUpdatesContext inWcauc) {
260: throw UnexpectedSystemException.notImplemented();
261: }
262: }
|