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.routetemplate;
018:
019: import java.sql.Timestamp;
020: import java.util.ArrayList;
021: import java.util.HashMap;
022: import java.util.Iterator;
023: import java.util.List;
024: import java.util.Map;
025:
026: import org.apache.commons.lang.builder.ToStringBuilder;
027:
028: import edu.iu.uis.eden.EdenConstants;
029: import edu.iu.uis.eden.KEWServiceLocator;
030: import edu.iu.uis.eden.WorkflowPersistable;
031: import edu.iu.uis.eden.lookupable.Field;
032: import edu.iu.uis.eden.lookupable.MyColumns;
033: import edu.iu.uis.eden.lookupable.Row;
034: import edu.iu.uis.eden.plugin.attributes.WorkflowAttribute;
035: import edu.iu.uis.eden.routeheader.DocumentContent;
036: import edu.iu.uis.eden.routetemplate.xmlrouting.GenericXMLRuleAttribute;
037: import edu.iu.uis.eden.util.CodeTranslator;
038: import edu.iu.uis.eden.util.Utilities;
039:
040: /**
041: * A model bean for a Rule within the KEW rules engine.
042: *
043: * @author rkirkend
044: * @author bmcgough
045: * @author jhopf
046: * @author ewestfal
047: */
048: public class RuleBaseValues implements WorkflowPersistable {
049:
050: private static final long serialVersionUID = 6137765574728530156L;
051: private Long ruleBaseValuesId;
052: private Long ruleTemplateId;
053: private Long previousVersionId;
054: private Boolean activeInd;
055: private String description;
056: private String docTypeName;
057: private Long routeHeaderId;
058: private Timestamp fromDate;
059: private Timestamp toDate;
060: private Timestamp deactivationDate;
061: private Boolean currentInd;
062: private Integer versionNbr;
063: private Integer lockVerNbr;
064: private Boolean ignorePrevious;
065: private List responsibilities;
066: private List ruleExtensions;
067: private RuleTemplate ruleTemplate;
068: private RuleBaseValues previousVersion;
069: private Timestamp activationDate;
070: private Boolean delegateRule = Boolean.FALSE;
071: private Boolean templateRuleInd = Boolean.FALSE;
072:
073: // required to be lookupable
074: private String returnUrl;
075: private String destinationUrl;
076: private MyColumns myColumns;
077:
078: public RuleBaseValues() {
079: responsibilities = new ArrayList();
080: ruleExtensions = new ArrayList();
081: }
082:
083: public Map getRuleExtensionValueLabels() {
084: Map extensionLabels = new HashMap();
085: for (Iterator iterator2 = getRuleExtensions().iterator(); iterator2
086: .hasNext();) {
087: RuleExtension ruleExtension = (RuleExtension) iterator2
088: .next();
089: if (!ruleExtension.getRuleTemplateAttribute()
090: .isWorkflowAttribute()) {
091: continue;
092: }
093: WorkflowAttribute workflowAttribute = ruleExtension
094: .getRuleTemplateAttribute().getWorkflowAttribute();
095:
096: RuleAttribute ruleAttribute = ruleExtension
097: .getRuleTemplateAttribute().getRuleAttribute();
098: if (ruleAttribute.getType().equals(
099: EdenConstants.RULE_XML_ATTRIBUTE_TYPE)) {
100: ((GenericXMLRuleAttribute) workflowAttribute)
101: .setRuleAttribute(ruleAttribute);
102: }
103: for (Iterator iterator = workflowAttribute.getRuleRows()
104: .iterator(); iterator.hasNext();) {
105: Row row = (Row) iterator.next();
106: for (Iterator iterator3 = row.getFields().iterator(); iterator3
107: .hasNext();) {
108: Field field = (Field) iterator3.next();
109: if (ruleAttribute.getType().equals(
110: EdenConstants.RULE_XML_ATTRIBUTE_TYPE)) {
111: extensionLabels.put(field.getPropertyName(),
112: field.getFieldLabel());
113: } else if (!Utilities.isEmpty(field
114: .getDefaultLookupableName())) {
115: extensionLabels.put(field
116: .getDefaultLookupableName(), field
117: .getFieldLabel());
118: } else {
119: extensionLabels.put(field.getPropertyName(),
120: field.getFieldLabel());
121: }
122: }
123: }
124: }
125: return extensionLabels;
126: }
127:
128: public String getRuleTemplateName() {
129: if (ruleTemplate != null) {
130: return ruleTemplate.getName();
131: }
132: return null;
133: }
134:
135: public RuleBaseValues getPreviousVersion() {
136: if (previousVersion == null) {
137: RuleService ruleService = (RuleService) KEWServiceLocator
138: .getService(KEWServiceLocator.RULE_SERVICE);
139: return ruleService
140: .findRuleBaseValuesById(previousVersionId);
141: }
142: return previousVersion;
143: }
144:
145: public void setPreviousVersion(RuleBaseValues previousVersion) {
146: this .previousVersion = previousVersion;
147: }
148:
149: public RuleResponsibility getResponsibility(int index) {
150: while (getResponsibilities().size() <= index) {
151: RuleResponsibility ruleResponsibility = new RuleResponsibility();
152: ruleResponsibility.setRuleBaseValues(this );
153: getResponsibilities().add(ruleResponsibility);
154: }
155: return (RuleResponsibility) getResponsibilities().get(index);
156: }
157:
158: public RuleExtension getRuleExtension(int index) {
159: while (getRuleExtensions().size() <= index) {
160: getRuleExtensions().add(new RuleExtension());
161: }
162: return (RuleExtension) getRuleExtensions().get(index);
163: }
164:
165: public RuleExtensionValue getRuleExtensionValue(String key) {
166: for (Iterator iter = getRuleExtensions().iterator(); iter
167: .hasNext();) {
168: RuleExtension ruleExtension = (RuleExtension) iter.next();
169: for (Iterator iterator = ruleExtension.getExtensionValues()
170: .iterator(); iterator.hasNext();) {
171: RuleExtensionValue ruleExtensionValue = (RuleExtensionValue) iterator
172: .next();
173: if (ruleExtensionValue.getKey().equals(key)) {
174: return ruleExtensionValue;
175: }
176: }
177: }
178: return null;
179: }
180:
181: public RuleExtensionValue getRuleExtensionValue(
182: Long ruleTemplateAttributeId, String key) {
183: for (Iterator iter = getRuleExtensions().iterator(); iter
184: .hasNext();) {
185: RuleExtension ruleExtension = (RuleExtension) iter.next();
186: if (ruleExtension.getRuleTemplateAttributeId().equals(
187: ruleTemplateAttributeId)) {
188: for (Iterator iterator = ruleExtension
189: .getExtensionValues().iterator(); iterator
190: .hasNext();) {
191: RuleExtensionValue ruleExtensionValue = (RuleExtensionValue) iterator
192: .next();
193: if (ruleExtensionValue.getKey().equals(key)) {
194: return ruleExtensionValue;
195: }
196: }
197: }
198: }
199: return null;
200: }
201:
202: public Long getPreviousVersionId() {
203: return previousVersionId;
204: }
205:
206: public void setPreviousVersionId(Long previousVersion) {
207: this .previousVersionId = previousVersion;
208: }
209:
210: public void addRuleResponsibility(
211: RuleResponsibility ruleResponsibility) {
212: addRuleResponsibility(ruleResponsibility, new Integer(
213: getResponsibilities().size()));
214: }
215:
216: public void addRuleResponsibility(
217: RuleResponsibility ruleResponsibility, Integer counter) {
218: boolean alreadyAdded = false;
219: int location = 0;
220: if (counter != null) {
221: for (Iterator responsibilitiesIter = getResponsibilities()
222: .iterator(); responsibilitiesIter.hasNext();) {
223: RuleResponsibility ruleResponsibilityRow = (RuleResponsibility) responsibilitiesIter
224: .next();
225: if (counter.intValue() == location) {
226: ruleResponsibilityRow
227: .setPriority(ruleResponsibility
228: .getPriority());
229: ruleResponsibilityRow
230: .setActionRequestedCd(ruleResponsibility
231: .getActionRequestedCd());
232: ruleResponsibilityRow
233: .setLockVerNbr(ruleResponsibility
234: .getLockVerNbr());
235: ruleResponsibilityRow
236: .setRuleBaseValuesId(ruleResponsibility
237: .getRuleBaseValuesId());
238: ruleResponsibilityRow
239: .setRuleResponsibilityName(ruleResponsibility
240: .getRuleResponsibilityName());
241: ruleResponsibilityRow
242: .setRuleResponsibilityType(ruleResponsibility
243: .getRuleResponsibilityType());
244: ruleResponsibilityRow
245: .setDelegationRules(ruleResponsibility
246: .getDelegationRules());
247: ruleResponsibilityRow
248: .setApprovePolicy(ruleResponsibility
249: .getApprovePolicy());
250: alreadyAdded = true;
251: }
252: location++;
253: }
254: }
255: if (!alreadyAdded) {
256: getResponsibilities().add(ruleResponsibility);
257: }
258: }
259:
260: public RuleTemplate getRuleTemplate() {
261: return ruleTemplate;
262: }
263:
264: public void setRuleTemplate(RuleTemplate ruleTemplate) {
265: this .ruleTemplate = ruleTemplate;
266: }
267:
268: public Long getRuleTemplateId() {
269: return ruleTemplateId;
270: }
271:
272: public void setRuleTemplateId(Long ruleTemplateId) {
273: this .ruleTemplateId = ruleTemplateId;
274: }
275:
276: public String getDocTypeName() {
277: return docTypeName;
278: }
279:
280: public void setDocTypeName(String docTypeName) {
281: this .docTypeName = docTypeName;
282: }
283:
284: public List getRuleExtensions() {
285: return ruleExtensions;
286: }
287:
288: public void setRuleExtensions(List ruleExtensions) {
289: this .ruleExtensions = ruleExtensions;
290: }
291:
292: public List getResponsibilities() {
293: return responsibilities;
294: }
295:
296: public void setResponsibilities(List responsibilities) {
297: this .responsibilities = responsibilities;
298: }
299:
300: public RuleResponsibility getResponsibility(
301: Long ruleResponsibilityKey) {
302: for (Iterator iterator = getResponsibilities().iterator(); iterator
303: .hasNext();) {
304: RuleResponsibility responsibility = (RuleResponsibility) iterator
305: .next();
306: if (responsibility.getRuleResponsibilityKey() != null
307: && responsibility.getRuleResponsibilityKey()
308: .equals(ruleResponsibilityKey)) {
309: return responsibility;
310: }
311: }
312: return null;
313: }
314:
315: public void removeResponsibility(int index) {
316: getResponsibilities().remove(index);
317: }
318:
319: public Boolean getActiveInd() {
320: return activeInd;
321: }
322:
323: public void setActiveInd(Boolean activeInd) {
324: this .activeInd = activeInd;
325: }
326:
327: public String getActiveIndDisplay() {
328: if (getActiveInd() == null) {
329: return EdenConstants.INACTIVE_LABEL_LOWER;
330: }
331: return CodeTranslator.getActiveIndicatorLabel(getActiveInd());
332: }
333:
334: public Boolean getCurrentInd() {
335: return currentInd;
336: }
337:
338: public void setCurrentInd(Boolean currentInd) {
339: this .currentInd = currentInd;
340: }
341:
342: public Timestamp getFromDate() {
343: return fromDate;
344: }
345:
346: public void setFromDate(Timestamp fromDate) {
347: this .fromDate = fromDate;
348: }
349:
350: public Integer getLockVerNbr() {
351: return lockVerNbr;
352: }
353:
354: public void setLockVerNbr(Integer lockVerNbr) {
355: this .lockVerNbr = lockVerNbr;
356: }
357:
358: public String getDescription() {
359: return description;
360: }
361:
362: public void setDescription(String description) {
363: this .description = description;
364: }
365:
366: public Long getRuleBaseValuesId() {
367: return ruleBaseValuesId;
368: }
369:
370: public void setRuleBaseValuesId(Long ruleBaseValuesId) {
371: this .ruleBaseValuesId = ruleBaseValuesId;
372: }
373:
374: public Timestamp getToDate() {
375: return toDate;
376: }
377:
378: public void setToDate(Timestamp toDate) {
379: this .toDate = toDate;
380: }
381:
382: public Integer getVersionNbr() {
383: return versionNbr;
384: }
385:
386: public void setVersionNbr(Integer versionNbr) {
387: this .versionNbr = versionNbr;
388: }
389:
390: public Object copy(boolean preserveKeys) {
391: RuleBaseValues ruleBaseValuesClone = new RuleBaseValues();
392:
393: if (preserveKeys && (ruleBaseValuesId != null)) {
394: ruleBaseValuesClone.setRuleBaseValuesId(new Long(
395: ruleBaseValuesId.longValue()));
396: }
397: if (routeHeaderId != null) {
398: ruleBaseValuesClone.setRouteHeaderId(new Long(routeHeaderId
399: .longValue()));
400: }
401: if (ignorePrevious != null) {
402: ruleBaseValuesClone.setIgnorePrevious(new Boolean(
403: ignorePrevious.booleanValue()));
404: }
405: if (activeInd != null) {
406: ruleBaseValuesClone.setActiveInd(new Boolean(activeInd
407: .booleanValue()));
408: }
409: if (currentInd != null) {
410: ruleBaseValuesClone.setCurrentInd(new Boolean(currentInd
411: .booleanValue()));
412: }
413: if (docTypeName != null) {
414: ruleBaseValuesClone.setDocTypeName(new String(docTypeName));
415: }
416: if (fromDate != null) {
417: ruleBaseValuesClone.setFromDate(new Timestamp(fromDate
418: .getTime()));
419: }
420: if (description != null) {
421: ruleBaseValuesClone.setDescription(new String(description));
422: }
423: if (delegateRule != null) {
424: ruleBaseValuesClone.setDelegateRule(new Boolean(
425: delegateRule.booleanValue()));
426: }
427: if ((responsibilities != null) && !responsibilities.isEmpty()) {
428: List responsibilityList = new ArrayList();
429:
430: for (Iterator i = responsibilities.iterator(); i.hasNext();) {
431: RuleResponsibility responsibility = (RuleResponsibility) i
432: .next();
433: RuleResponsibility responsibilityCopy = (RuleResponsibility) responsibility
434: .copy(false);
435: responsibilityCopy
436: .setRuleBaseValues(ruleBaseValuesClone);
437: responsibilityList.add(responsibilityCopy);
438: }
439: ruleBaseValuesClone.setResponsibilities(responsibilityList);
440: }
441:
442: if ((ruleExtensions != null) && !ruleExtensions.isEmpty()) {
443: List ruleExtensionsList = new ArrayList();
444:
445: for (Iterator i = ruleExtensions.iterator(); i.hasNext();) {
446: RuleExtension ruleExtension = (RuleExtension) i.next();
447: RuleExtension ruleExtensionCopy = (RuleExtension) ruleExtension
448: .copy(preserveKeys);
449: ruleExtensionCopy
450: .setRuleBaseValues(ruleBaseValuesClone);
451: ruleExtensionsList.add(ruleExtensionCopy);
452: }
453: ruleBaseValuesClone.setRuleExtensions(ruleExtensionsList);
454: }
455: if (toDate != null) {
456: ruleBaseValuesClone.setToDate(new Timestamp(toDate
457: .getTime()));
458: }
459: if (versionNbr != null) {
460: ruleBaseValuesClone.setVersionNbr(new Integer(versionNbr
461: .intValue()));
462: }
463: ruleBaseValuesClone.setActivationDate(getActivationDate());
464: ruleBaseValuesClone.setRuleTemplate(getRuleTemplate());
465: return ruleBaseValuesClone;
466: }
467:
468: public String getReturnUrl() {
469: return returnUrl;
470: }
471:
472: public void setReturnUrl(String returnUrl) {
473: this .returnUrl = returnUrl;
474: }
475:
476: public String getFromDateString() {
477: if (this .fromDate != null) {
478: return EdenConstants.getDefaultDateFormat().format(
479: this .fromDate);
480: }
481: return null;
482: }
483:
484: public void setFromDateString(String fromDateString) {
485: try {
486: this .fromDate = new Timestamp(EdenConstants
487: .getDefaultDateFormat().parse(fromDateString)
488: .getTime());
489: } catch (Exception e) {
490: }
491: }
492:
493: public String getToDateString() {
494: if (this .toDate != null) {
495: return EdenConstants.getDefaultDateFormat().format(
496: this .toDate);
497: }
498: return null;
499: }
500:
501: public void setToDateString(String toDateString) {
502: try {
503: this .toDate = new Timestamp(EdenConstants
504: .getDefaultDateFormat().parse(toDateString)
505: .getTime());
506: } catch (Exception e) {
507: }
508: }
509:
510: public Boolean getIgnorePrevious() {
511: return ignorePrevious;
512: }
513:
514: public void setIgnorePrevious(Boolean ignorePrevious) {
515: this .ignorePrevious = ignorePrevious;
516: }
517:
518: public boolean isMatch(DocumentContent docContent) {
519: for (Iterator iter = getRuleTemplate()
520: .getRuleTemplateAttributes().iterator(); iter.hasNext();) {
521: RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter
522: .next();
523: if (!ruleTemplateAttribute.isWorkflowAttribute()) {
524: continue;
525: }
526: WorkflowAttribute routingAttribute = (WorkflowAttribute) ruleTemplateAttribute
527: .getWorkflowAttribute();
528:
529: RuleAttribute ruleAttribute = ruleTemplateAttribute
530: .getRuleAttribute();
531: if (ruleAttribute.getType().equals(
532: EdenConstants.RULE_XML_ATTRIBUTE_TYPE)) {
533: ((GenericXMLRuleAttribute) routingAttribute)
534: .setRuleAttribute(ruleAttribute);
535: }
536: String className = ruleAttribute.getClassName();
537: List editedRuleExtensions = new ArrayList();
538: for (Iterator iter2 = getRuleExtensions().iterator(); iter2
539: .hasNext();) {
540: RuleExtension extension = (RuleExtension) iter2.next();
541: if (extension.getRuleTemplateAttribute()
542: .getRuleAttribute().getClassName().equals(
543: className)) {
544: editedRuleExtensions.add(extension);
545: }
546: }
547: if (!routingAttribute.isMatch(docContent,
548: editedRuleExtensions)) {
549: return false;
550: }
551: }
552: return true;
553: }
554:
555: public RuleResponsibility findResponsibility(String roleName) {
556: for (Iterator iter = getResponsibilities().iterator(); iter
557: .hasNext();) {
558: RuleResponsibility resp = (RuleResponsibility) iter.next();
559: if (EdenConstants.RULE_RESPONSIBILITY_ROLE_ID.equals(resp
560: .getRuleResponsibilityType())
561: && roleName
562: .equals(resp.getRuleResponsibilityName())) {
563: return resp;
564: }
565: }
566: return null;
567: }
568:
569: public Long getRouteHeaderId() {
570: return routeHeaderId;
571: }
572:
573: public void setRouteHeaderId(Long routeHeaderId) {
574: this .routeHeaderId = routeHeaderId;
575: }
576:
577: public Boolean getDelegateRule() {
578: return delegateRule;
579: }
580:
581: public void setDelegateRule(Boolean isDelegateRule) {
582: this .delegateRule = isDelegateRule;
583: }
584:
585: public Timestamp getActivationDate() {
586: return activationDate;
587: }
588:
589: public void setActivationDate(Timestamp activationDate) {
590: this .activationDate = activationDate;
591: }
592:
593: public MyColumns getMyColumns() {
594: return myColumns;
595: }
596:
597: public void setMyColumns(MyColumns additionalColumns) {
598: this .myColumns = additionalColumns;
599: }
600:
601: public String getDestinationUrl() {
602: return destinationUrl;
603: }
604:
605: public void setDestinationUrl(String destinationUrl) {
606: this .destinationUrl = destinationUrl;
607: }
608:
609: public Timestamp getDeactivationDate() {
610: return deactivationDate;
611: }
612:
613: public void setDeactivationDate(Timestamp deactivationDate) {
614: this .deactivationDate = deactivationDate;
615: }
616:
617: public Boolean getTemplateRuleInd() {
618: return templateRuleInd;
619: }
620:
621: public void setTemplateRuleInd(Boolean templateRuleInd) {
622: this .templateRuleInd = templateRuleInd;
623: }
624:
625: public String toString() {
626: return new ToStringBuilder(this ).append("ruleBaseValuesId",
627: ruleBaseValuesId).append("description", description)
628: .append("docTypeName", docTypeName).append(
629: "routeHeaderId", routeHeaderId).append(
630: "delegateRule", delegateRule).append(
631: "ignorePrevious", ignorePrevious).append(
632: "activeInd", activeInd).append("currentInd",
633: currentInd).append("versionNbr", versionNbr)
634: .append("previousVersionId", previousVersionId).append(
635: "ruleTemplateId", ruleTemplateId).append(
636: "returnUrl", returnUrl).append(
637: "responsibilities",
638: responsibilities == null ? responsibilities
639: : "size: " + responsibilities.size())
640: .append("lockVerNbr", lockVerNbr).toString();
641: }
642: }
|