1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package edu.sampleu.travel.workflow;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.kuali.rice.core.api.uif.RemotableAttributeErrorContract;
25  import org.kuali.rice.core.api.uif.RemotableAttributeError;
26  import org.kuali.rice.kew.rule.GenericWorkflowAttribute;
27  import org.kuali.rice.kns.web.ui.Field;
28  import org.kuali.rice.kns.web.ui.Row;
29  
30  public class DestinationRuleAttribute extends GenericWorkflowAttribute {
31  
32  	private static final String DEST_LABEL = "Destination";
33  	private static final String DEST_FIELD_KEY = "destination";
34  
35      private final List<Row> rows = new ArrayList<Row>();
36  
37  	private String destination;
38  
39      public DestinationRuleAttribute() {
40          super("destination");
41      }
42  
43      public DestinationRuleAttribute(String destination) {
44          super("destination");
45          this.destination = destination;
46      }
47  
48      
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  	public List<Row> getRuleRows() {
81  		return getRows();
82  	}
83  
84  	public List<Row> getRoutingDataRows() {
85  		return getRows();
86  	}
87  
88      private List<Row> getRows() {
89          log.info("Returning rows: " + rows);
90          List<Field> fields = new ArrayList<Field>();
91          fields.add(new Field(DEST_LABEL, "", Field.TEXT, false, DEST_FIELD_KEY, "", false, false, null, null));
92          List<Row> rows = new ArrayList<Row>();
93          rows.add(new Row(fields));
94          return rows;
95      }
96  
97      
98      public void setDestination(String destination) {
99          this.destination = destination;
100     }
101 
102     public Map<String, String> getProperties() {
103         Map<String, String> props = new HashMap<String, String>();
104         props.put("destination", destination);
105         return props;
106     }
107 
108 	public List<RemotableAttributeError> validateRoutingData(Map paramMap) {
109 		return validateInputMap(paramMap);
110 	}
111 
112 	public List<RemotableAttributeError> validateRuleData(Map paramMap) {
113 		return validateInputMap(paramMap);
114 	}
115 
116     private List<RemotableAttributeError> validateInputMap(Map paramMap) {
117     	List errors = new ArrayList();
118     	this.destination = (String) paramMap.get(DEST_FIELD_KEY);
119     	if (StringUtils.isBlank(destination)  && required) {
120     		errors.add(RemotableAttributeError.Builder.create(DEST_FIELD_KEY, "Destination is required.").build());
121     	}
122     	return errors;
123     }
124 }