KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > spi > memory > MemoryWorkflowStore


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.workflow.spi.memory;
6
7 import com.opensymphony.module.propertyset.PropertySet;
8 import com.opensymphony.module.propertyset.PropertySetManager;
9
10 import com.opensymphony.util.DataUtil;
11 import com.opensymphony.util.TextUtils;
12
13 import com.opensymphony.workflow.StoreException;
14 import com.opensymphony.workflow.query.Expression;
15 import com.opensymphony.workflow.query.FieldExpression;
16 import com.opensymphony.workflow.query.NestedExpression;
17 import com.opensymphony.workflow.query.WorkflowExpressionQuery;
18 import com.opensymphony.workflow.query.WorkflowQuery;
19 import com.opensymphony.workflow.spi.SimpleStep;
20 import com.opensymphony.workflow.spi.SimpleWorkflowEntry;
21 import com.opensymphony.workflow.spi.Step;
22 import com.opensymphony.workflow.spi.WorkflowEntry;
23 import com.opensymphony.workflow.spi.WorkflowStore;
24
25 import java.security.InvalidParameterException JavaDoc;
26
27 import java.util.*;
28
29
30 /**
31  * Simple memory implementation.
32  *
33  * @author <a HREF="mailto:plightbo@hotmail.com">Pat Lightbody</a>
34  */

35 public class MemoryWorkflowStore implements WorkflowStore {
36     //~ Static fields/initializers /////////////////////////////////////////////
37

38     private static HashMap entryCache = new HashMap();
39     private static HashMap currentStepsCache = new HashMap();
40     private static HashMap historyStepsCache = new HashMap();
41     private static HashMap propertySetCache = new HashMap();
42     private static long globalEntryId = 1;
43     private static long globalStepId = 1;
44
45     //~ Methods ////////////////////////////////////////////////////////////////
46

47     public void setEntryState(long entryId, int state) throws StoreException {
48         SimpleWorkflowEntry theEntry = (SimpleWorkflowEntry) findEntry(entryId);
49         theEntry.setState(state);
50     }
51
52     public PropertySet getPropertySet(long entryId) {
53         PropertySet ps = (PropertySet) propertySetCache.get(new Long JavaDoc(entryId));
54
55         if (ps == null) {
56             ps = PropertySetManager.getInstance("memory", null);
57             propertySetCache.put(new Long JavaDoc(entryId), ps);
58         }
59
60         return ps;
61     }
62
63     public Step createCurrentStep(long entryId, int stepId, String JavaDoc owner, Date startDate, Date dueDate, String JavaDoc status, long[] previousIds) {
64         long id = globalStepId++;
65         SimpleStep step = new SimpleStep(id, entryId, stepId, 0, owner, startDate, dueDate, null, status, previousIds, null);
66
67         List currentSteps = (List) currentStepsCache.get(new Long JavaDoc(entryId));
68
69         if (currentSteps == null) {
70             currentSteps = new ArrayList();
71             currentStepsCache.put(new Long JavaDoc(entryId), currentSteps);
72         }
73
74         currentSteps.add(step);
75
76         return step;
77     }
78
79     /**
80      * Reset the MemoryWorkflowStore so it doesn't have any information.
81      * Useful when testing and you don't want the MemoryWorkflowStore to
82      * have old data in it.
83      */

84     public static void reset() {
85         entryCache.clear();
86         currentStepsCache.clear();
87         historyStepsCache.clear();
88         propertySetCache.clear();
89     }
90
91     public WorkflowEntry createEntry(String JavaDoc workflowName) {
92         long id = globalEntryId++;
93         SimpleWorkflowEntry entry = new SimpleWorkflowEntry(id, workflowName, WorkflowEntry.CREATED);
94         entryCache.put(new Long JavaDoc(id), entry);
95
96         return entry;
97     }
98
99     public List findCurrentSteps(long entryId) {
100         List currentSteps = (List) currentStepsCache.get(new Long JavaDoc(entryId));
101
102         if (currentSteps == null) {
103             currentSteps = new ArrayList();
104             currentStepsCache.put(new Long JavaDoc(entryId), currentSteps);
105         }
106
107         return currentSteps;
108     }
109
110     public WorkflowEntry findEntry(long entryId) {
111         return (WorkflowEntry) entryCache.get(new Long JavaDoc(entryId));
112     }
113
114     public List findHistorySteps(long entryId) {
115         List historySteps = (List) historyStepsCache.get(new Long JavaDoc(entryId));
116
117         if (historySteps == null) {
118             historySteps = new ArrayList();
119             historyStepsCache.put(new Long JavaDoc(entryId), historySteps);
120         }
121
122         return historySteps;
123     }
124
125     public void init(Map props) {
126     }
127
128     public Step markFinished(Step step, int actionId, Date finishDate, String JavaDoc status, String JavaDoc caller) {
129         List currentSteps = (List) currentStepsCache.get(new Long JavaDoc(step.getEntryId()));
130
131         for (Iterator iterator = currentSteps.iterator(); iterator.hasNext();) {
132             SimpleStep theStep = (SimpleStep) iterator.next();
133
134             if (theStep.getId() == step.getId()) {
135                 theStep.setStatus(status);
136                 theStep.setActionId(actionId);
137                 theStep.setFinishDate(finishDate);
138                 theStep.setCaller(caller);
139
140                 return theStep;
141             }
142         }
143
144         return null;
145     }
146
147     public void moveToHistory(Step step) {
148         List currentSteps = (List) currentStepsCache.get(new Long JavaDoc(step.getEntryId()));
149
150         List historySteps = (List) historyStepsCache.get(new Long JavaDoc(step.getEntryId()));
151
152         if (historySteps == null) {
153             historySteps = new ArrayList();
154             historyStepsCache.put(new Long JavaDoc(step.getEntryId()), historySteps);
155         }
156
157         SimpleStep simpleStep = (SimpleStep) step;
158
159         for (Iterator iterator = currentSteps.iterator(); iterator.hasNext();) {
160             Step currentStep = (Step) iterator.next();
161
162             if (simpleStep.getId() == currentStep.getId()) {
163                 iterator.remove();
164                 historySteps.add(simpleStep);
165
166                 break;
167             }
168         }
169     }
170
171     public List query(WorkflowQuery query) {
172         ArrayList results = new ArrayList();
173
174         for (Iterator iterator = entryCache.entrySet().iterator();
175                 iterator.hasNext();) {
176             Map.Entry mapEntry = (Map.Entry) iterator.next();
177             Long JavaDoc entryId = (Long JavaDoc) mapEntry.getKey();
178
179             if (query(entryId, query)) {
180                 results.add(entryId);
181             }
182         }
183
184         return results;
185     }
186
187     public List query(WorkflowExpressionQuery query) {
188         ArrayList results = new ArrayList();
189
190         for (Iterator iterator = entryCache.entrySet().iterator();
191                 iterator.hasNext();) {
192             Map.Entry mapEntry = (Map.Entry) iterator.next();
193             Long JavaDoc entryId = (Long JavaDoc) mapEntry.getKey();
194
195             if (query(entryId.longValue(), query)) {
196                 results.add(entryId);
197             }
198         }
199
200         return results;
201     }
202
203     private boolean checkExpression(long entryId, FieldExpression expression) {
204         Object JavaDoc value = expression.getValue();
205         int operator = expression.getOperator();
206         int field = expression.getField();
207         int context = expression.getContext();
208
209         Long JavaDoc id = new Long JavaDoc(entryId);
210
211         if (context == FieldExpression.ENTRY) {
212             SimpleWorkflowEntry theEntry = (SimpleWorkflowEntry) entryCache.get(id);
213
214             if (field == FieldExpression.NAME) {
215                 return this.compareText(theEntry.getWorkflowName(), (String JavaDoc) value, operator);
216             }
217
218             if (field == FieldExpression.STATE) {
219                 return this.compareLong(DataUtil.getInt((Integer JavaDoc) value), theEntry.getState(), operator);
220             }
221
222             throw new InvalidParameterException JavaDoc("unknown field");
223         }
224
225         List steps;
226
227         if (context == FieldExpression.CURRENT_STEPS) {
228             steps = (List) currentStepsCache.get(id);
229         } else if (context == FieldExpression.HISTORY_STEPS) {
230             steps = (List) historyStepsCache.get(id);
231         } else {
232             throw new InvalidParameterException JavaDoc("unknown field context");
233         }
234
235         if (steps == null) {
236             return false;
237         }
238
239         boolean expressionResult = false;
240
241         switch (field) {
242         case FieldExpression.ACTION:
243
244             long actionId = DataUtil.getInt((Integer JavaDoc) value);
245
246             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
247                 SimpleStep step = (SimpleStep) iterator.next();
248
249                 if (this.compareLong(step.getActionId(), actionId, operator)) {
250                     expressionResult = true;
251
252                     break;
253                 }
254             }
255
256             break;
257
258         case FieldExpression.CALLER:
259
260             String JavaDoc caller = (String JavaDoc) value;
261
262             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
263                 SimpleStep step = (SimpleStep) iterator.next();
264
265                 if (this.compareText(step.getCaller(), caller, operator)) {
266                     expressionResult = true;
267
268                     break;
269                 }
270             }
271
272             break;
273
274         case FieldExpression.FINISH_DATE:
275
276             Date finishDate = (Date) value;
277
278             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
279                 SimpleStep step = (SimpleStep) iterator.next();
280
281                 if (this.compareDate(step.getFinishDate(), finishDate, operator)) {
282                     expressionResult = true;
283
284                     break;
285                 }
286             }
287
288             break;
289
290         case FieldExpression.OWNER:
291
292             String JavaDoc owner = (String JavaDoc) value;
293
294             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
295                 SimpleStep step = (SimpleStep) iterator.next();
296
297                 if (this.compareText(step.getOwner(), owner, operator)) {
298                     expressionResult = true;
299
300                     break;
301                 }
302             }
303
304             break;
305
306         case FieldExpression.START_DATE:
307
308             Date startDate = (Date) value;
309
310             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
311                 SimpleStep step = (SimpleStep) iterator.next();
312
313                 if (this.compareDate(step.getStartDate(), startDate, operator)) {
314                     expressionResult = true;
315
316                     break;
317                 }
318             }
319
320             break;
321
322         case FieldExpression.STEP:
323
324             int stepId = DataUtil.getInt((Integer JavaDoc) value);
325
326             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
327                 SimpleStep step = (SimpleStep) iterator.next();
328
329                 if (this.compareLong(step.getStepId(), stepId, operator)) {
330                     expressionResult = true;
331
332                     break;
333                 }
334             }
335
336             break;
337
338         case FieldExpression.STATUS:
339
340             String JavaDoc status = (String JavaDoc) value;
341
342             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
343                 SimpleStep step = (SimpleStep) iterator.next();
344
345                 if (this.compareText(step.getStatus(), status, operator)) {
346                     expressionResult = true;
347
348                     break;
349                 }
350             }
351
352             break;
353         }
354
355         if (expression.isNegate()) {
356             return !expressionResult;
357         } else {
358             return expressionResult;
359         }
360     }
361
362     private boolean checkNestedExpression(long entryId, NestedExpression nestedExpression) {
363         for (int i = 0; i < nestedExpression.getExpressionCount(); i++) {
364             boolean expressionResult;
365             Expression expression = nestedExpression.getExpression(i);
366
367             if (expression.isNested()) {
368                 expressionResult = this.checkNestedExpression(entryId, (NestedExpression) expression);
369             } else {
370                 expressionResult = this.checkExpression(entryId, (FieldExpression) expression);
371             }
372
373             if (nestedExpression.getExpressionOperator() == NestedExpression.AND) {
374                 if (expressionResult == false) {
375                     return nestedExpression.isNegate();
376                 }
377             } else if (nestedExpression.getExpressionOperator() == NestedExpression.OR) {
378                 if (expressionResult == true) {
379                     return !nestedExpression.isNegate();
380                 }
381             }
382         }
383
384         if (nestedExpression.getExpressionOperator() == NestedExpression.AND) {
385             return !nestedExpression.isNegate();
386         } else if (nestedExpression.getExpressionOperator() == NestedExpression.OR) {
387             return nestedExpression.isNegate();
388         }
389
390         throw new InvalidParameterException JavaDoc("unknown operator");
391     }
392
393     private boolean compareDate(Date value1, Date value2, int operator) {
394         switch (operator) {
395         case FieldExpression.EQUALS:
396             return value1.compareTo(value2) == 0;
397
398         case FieldExpression.NOT_EQUALS:
399             return value1.compareTo(value2) != 0;
400
401         case FieldExpression.GT:
402             return (value1.compareTo(value2) > 0);
403
404         case FieldExpression.LT:
405             return value1.compareTo(value2) < 0;
406         }
407
408         throw new InvalidParameterException JavaDoc("unknown field operator");
409     }
410
411     private boolean compareLong(long value1, long value2, int operator) {
412         switch (operator) {
413         case FieldExpression.EQUALS:
414             return value1 == value2;
415
416         case FieldExpression.NOT_EQUALS:
417             return value1 != value2;
418
419         case FieldExpression.GT:
420             return value1 > value2;
421
422         case FieldExpression.LT:
423             return value1 < value2;
424         }
425
426         throw new InvalidParameterException JavaDoc("unknown field operator");
427     }
428
429     private boolean compareText(String JavaDoc value1, String JavaDoc value2, int operator) {
430         switch (operator) {
431         case FieldExpression.EQUALS:
432             return TextUtils.noNull(value1).equals(value2);
433
434         case FieldExpression.NOT_EQUALS:
435             return !TextUtils.noNull(value1).equals(value2);
436
437         case FieldExpression.GT:
438             return TextUtils.noNull(value1).compareTo(value2) > 0;
439
440         case FieldExpression.LT:
441             return TextUtils.noNull(value1).compareTo(value2) < 0;
442         }
443
444         throw new InvalidParameterException JavaDoc("unknown field operator");
445     }
446
447     private boolean query(Long JavaDoc entryId, WorkflowQuery query) {
448         if (query.getLeft() == null) {
449             return queryBasic(entryId, query);
450         } else {
451             int operator = query.getOperator();
452             WorkflowQuery left = query.getLeft();
453             WorkflowQuery right = query.getRight();
454
455             switch (operator) {
456             case WorkflowQuery.AND:
457                 return query(entryId, left) && query(entryId, right);
458
459             case WorkflowQuery.OR:
460                 return query(entryId, left) || query(entryId, right);
461
462             case WorkflowQuery.XOR:
463                 return query(entryId, left) ^ query(entryId, right);
464             }
465         }
466
467         return false;
468     }
469
470     private boolean query(long entryId, WorkflowExpressionQuery query) {
471         Expression expression = query.getExpression();
472
473         if (expression.isNested()) {
474             return this.checkNestedExpression(entryId, (NestedExpression) expression);
475         } else {
476             return this.checkExpression(entryId, (FieldExpression) expression);
477         }
478     }
479
480     private boolean queryBasic(Long JavaDoc entryId, WorkflowQuery query) {
481         // the query object is a comparison
482
Object JavaDoc value = query.getValue();
483         int operator = query.getOperator();
484         int field = query.getField();
485         int type = query.getType();
486
487         switch (operator) {
488         case WorkflowQuery.EQUALS:
489             return queryEquals(entryId, field, type, value);
490
491         case WorkflowQuery.NOT_EQUALS:
492             return queryNotEquals(entryId, field, type, value);
493
494         case WorkflowQuery.GT:
495             return queryGreaterThan(entryId, field, type, value);
496
497         case WorkflowQuery.LT:
498             return queryLessThan(entryId, field, type, value);
499         }
500
501         return false;
502     }
503
504     private boolean queryEquals(Long JavaDoc entryId, int field, int type, Object JavaDoc value) {
505         List steps;
506
507         if (type == WorkflowQuery.CURRENT) {
508             steps = (List) currentStepsCache.get(entryId);
509         } else {
510             steps = (List) historyStepsCache.get(entryId);
511         }
512
513         switch (field) {
514         case WorkflowQuery.ACTION:
515
516             long actionId = DataUtil.getInt((Integer JavaDoc) value);
517
518             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
519                 SimpleStep step = (SimpleStep) iterator.next();
520
521                 if (step.getActionId() == actionId) {
522                     return true;
523                 }
524             }
525
526             return false;
527
528         case WorkflowQuery.CALLER:
529
530             String JavaDoc caller = (String JavaDoc) value;
531
532             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
533                 SimpleStep step = (SimpleStep) iterator.next();
534
535                 if (TextUtils.noNull(step.getCaller()).equals(caller)) {
536                     return true;
537                 }
538             }
539
540             return false;
541
542         case WorkflowQuery.FINISH_DATE:
543
544             Date finishDate = (Date) value;
545
546             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
547                 SimpleStep step = (SimpleStep) iterator.next();
548
549                 if (finishDate.equals(step.getFinishDate())) {
550                     return true;
551                 }
552             }
553
554             return false;
555
556         case WorkflowQuery.OWNER:
557
558             String JavaDoc owner = (String JavaDoc) value;
559
560             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
561                 SimpleStep step = (SimpleStep) iterator.next();
562
563                 if (TextUtils.noNull(step.getOwner()).equals(owner)) {
564                     return true;
565                 }
566             }
567
568             return false;
569
570         case WorkflowQuery.START_DATE:
571
572             Date startDate = (Date) value;
573
574             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
575                 SimpleStep step = (SimpleStep) iterator.next();
576
577                 if (startDate.equals(step.getStartDate())) {
578                     return true;
579                 }
580             }
581
582             return false;
583
584         case WorkflowQuery.STEP:
585
586             int stepId = DataUtil.getInt((Integer JavaDoc) value);
587
588             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
589                 SimpleStep step = (SimpleStep) iterator.next();
590
591                 if (stepId == step.getStepId()) {
592                     return true;
593                 }
594             }
595
596             return false;
597
598         case WorkflowQuery.STATUS:
599
600             String JavaDoc status = (String JavaDoc) value;
601
602             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
603                 SimpleStep step = (SimpleStep) iterator.next();
604
605                 if (TextUtils.noNull(step.getStatus()).equals(status)) {
606                     return true;
607                 }
608             }
609
610             return false;
611         }
612
613         return false;
614     }
615
616     private boolean queryGreaterThan(Long JavaDoc entryId, int field, int type, Object JavaDoc value) {
617         List steps;
618
619         if (type == WorkflowQuery.CURRENT) {
620             steps = (List) currentStepsCache.get(entryId);
621         } else {
622             steps = (List) historyStepsCache.get(entryId);
623         }
624
625         switch (field) {
626         case WorkflowQuery.ACTION:
627
628             long actionId = DataUtil.getLong((Long JavaDoc) value);
629
630             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
631                 SimpleStep step = (SimpleStep) iterator.next();
632
633                 if (step.getActionId() > actionId) {
634                     return true;
635                 }
636             }
637
638             return false;
639
640         case WorkflowQuery.CALLER:
641
642             String JavaDoc caller = (String JavaDoc) value;
643
644             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
645                 SimpleStep step = (SimpleStep) iterator.next();
646
647                 if (TextUtils.noNull(step.getCaller()).compareTo(caller) > 0) {
648                     return true;
649                 }
650             }
651
652             return false;
653
654         case WorkflowQuery.FINISH_DATE:
655
656             Date finishDate = (Date) value;
657
658             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
659                 SimpleStep step = (SimpleStep) iterator.next();
660
661                 if (step.getFinishDate().compareTo(finishDate) > 0) {
662                     return true;
663                 }
664             }
665
666             return false;
667
668         case WorkflowQuery.OWNER:
669
670             String JavaDoc owner = (String JavaDoc) value;
671
672             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
673                 SimpleStep step = (SimpleStep) iterator.next();
674
675                 if (TextUtils.noNull(step.getOwner()).compareTo(owner) > 0) {
676                     return true;
677                 }
678             }
679
680             return false;
681
682         case WorkflowQuery.START_DATE:
683
684             Date startDate = (Date) value;
685
686             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
687                 SimpleStep step = (SimpleStep) iterator.next();
688
689                 if (step.getStartDate().compareTo(startDate) > 0) {
690                     return true;
691                 }
692             }
693
694             return false;
695
696         case WorkflowQuery.STEP:
697
698             int stepId = DataUtil.getInt((Integer JavaDoc) value);
699
700             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
701                 SimpleStep step = (SimpleStep) iterator.next();
702
703                 if (step.getStepId() > stepId) {
704                     return true;
705                 }
706             }
707
708             return false;
709
710         case WorkflowQuery.STATUS:
711
712             String JavaDoc status = (String JavaDoc) value;
713
714             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
715                 SimpleStep step = (SimpleStep) iterator.next();
716
717                 if (TextUtils.noNull(step.getStatus()).compareTo(status) > 0) {
718                     return true;
719                 }
720             }
721
722             return false;
723         }
724
725         return false;
726     }
727
728     private boolean queryLessThan(Long JavaDoc entryId, int field, int type, Object JavaDoc value) {
729         List steps;
730
731         if (type == WorkflowQuery.CURRENT) {
732             steps = (List) currentStepsCache.get(entryId);
733         } else {
734             steps = (List) historyStepsCache.get(entryId);
735         }
736
737         switch (field) {
738         case WorkflowQuery.ACTION:
739
740             long actionId = DataUtil.getLong((Long JavaDoc) value);
741
742             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
743                 SimpleStep step = (SimpleStep) iterator.next();
744
745                 if (step.getActionId() < actionId) {
746                     return true;
747                 }
748             }
749
750             return false;
751
752         case WorkflowQuery.CALLER:
753
754             String JavaDoc caller = (String JavaDoc) value;
755
756             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
757                 SimpleStep step = (SimpleStep) iterator.next();
758
759                 if (TextUtils.noNull(step.getCaller()).compareTo(caller) < 0) {
760                     return true;
761                 }
762             }
763
764             return false;
765
766         case WorkflowQuery.FINISH_DATE:
767
768             Date finishDate = (Date) value;
769
770             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
771                 SimpleStep step = (SimpleStep) iterator.next();
772
773                 if (step.getFinishDate().compareTo(finishDate) < 0) {
774                     return true;
775                 }
776             }
777
778             return false;
779
780         case WorkflowQuery.OWNER:
781
782             String JavaDoc owner = (String JavaDoc) value;
783
784             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
785                 SimpleStep step = (SimpleStep) iterator.next();
786
787                 if (TextUtils.noNull(step.getOwner()).compareTo(owner) < 0) {
788                     return true;
789                 }
790             }
791
792             return false;
793
794         case WorkflowQuery.START_DATE:
795
796             Date startDate = (Date) value;
797
798             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
799                 SimpleStep step = (SimpleStep) iterator.next();
800
801                 if (step.getStartDate().compareTo(startDate) < 0) {
802                     return true;
803                 }
804             }
805
806             return false;
807
808         case WorkflowQuery.STEP:
809
810             int stepId = DataUtil.getInt((Integer JavaDoc) value);
811
812             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
813                 SimpleStep step = (SimpleStep) iterator.next();
814
815                 if (step.getStepId() < stepId) {
816                     return true;
817                 }
818             }
819
820             return false;
821
822         case WorkflowQuery.STATUS:
823
824             String JavaDoc status = (String JavaDoc) value;
825
826             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
827                 SimpleStep step = (SimpleStep) iterator.next();
828
829                 if (TextUtils.noNull(step.getStatus()).compareTo(status) < 0) {
830                     return true;
831                 }
832             }
833
834             return false;
835         }
836
837         return false;
838     }
839
840     private boolean queryNotEquals(Long JavaDoc entryId, int field, int type, Object JavaDoc value) {
841         List steps;
842
843         if (type == WorkflowQuery.CURRENT) {
844             steps = (List) currentStepsCache.get(entryId);
845         } else {
846             steps = (List) historyStepsCache.get(entryId);
847         }
848
849         switch (field) {
850         case WorkflowQuery.ACTION:
851
852             long actionId = DataUtil.getLong((Long JavaDoc) value);
853
854             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
855                 SimpleStep step = (SimpleStep) iterator.next();
856
857                 if (step.getActionId() != actionId) {
858                     return true;
859                 }
860             }
861
862             return false;
863
864         case WorkflowQuery.CALLER:
865
866             String JavaDoc caller = (String JavaDoc) value;
867
868             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
869                 SimpleStep step = (SimpleStep) iterator.next();
870
871                 if (!TextUtils.noNull(step.getCaller()).equals(caller)) {
872                     return true;
873                 }
874             }
875
876             return false;
877
878         case WorkflowQuery.FINISH_DATE:
879
880             Date finishDate = (Date) value;
881
882             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
883                 SimpleStep step = (SimpleStep) iterator.next();
884
885                 if (!finishDate.equals(step.getFinishDate())) {
886                     return true;
887                 }
888             }
889
890             return false;
891
892         case WorkflowQuery.OWNER:
893
894             String JavaDoc owner = (String JavaDoc) value;
895
896             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
897                 SimpleStep step = (SimpleStep) iterator.next();
898
899                 if (!TextUtils.noNull(step.getOwner()).equals(owner)) {
900                     return true;
901                 }
902             }
903
904             return false;
905
906         case WorkflowQuery.START_DATE:
907
908             Date startDate = (Date) value;
909
910             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
911                 SimpleStep step = (SimpleStep) iterator.next();
912
913                 if (!startDate.equals(step.getStartDate())) {
914                     return true;
915                 }
916             }
917
918             return false;
919
920         case WorkflowQuery.STEP:
921
922             int stepId = DataUtil.getInt((Integer JavaDoc) value);
923
924             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
925                 SimpleStep step = (SimpleStep) iterator.next();
926
927                 if (stepId != step.getStepId()) {
928                     return true;
929                 }
930             }
931
932             return false;
933
934         case WorkflowQuery.STATUS:
935
936             String JavaDoc status = (String JavaDoc) value;
937
938             for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
939                 SimpleStep step = (SimpleStep) iterator.next();
940
941                 if (!TextUtils.noNull(step.getStatus()).equals(status)) {
942                     return true;
943                 }
944             }
945
946             return false;
947         }
948
949         return false;
950     }
951 }
952
Popular Tags