View Javadoc
1   package org.kuali.ole.alert.keyValue;
2   
3   import org.kuali.ole.alert.bo.AlertEvent;
4   import org.kuali.ole.alert.bo.AlertField;
5   import org.kuali.rice.core.api.util.ConcreteKeyValue;
6   import org.kuali.rice.core.api.util.KeyValue;
7   import org.kuali.rice.krad.maintenance.MaintenanceDocument;
8   import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
9   import org.kuali.rice.krad.uif.view.ViewModel;
10  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
11  
12  import java.lang.annotation.Annotation;
13  import java.lang.reflect.Field;
14  import java.util.ArrayList;
15  import java.util.List;
16  
17  /**
18   * Created by arunag on 8/27/14.
19   */
20  public class AlertFieldValueFinder extends UifKeyValuesFinderBase {
21  
22  
23  
24      public List<KeyValue> getKeyValues(ViewModel viewModel) {
25  
26  /*        MaintenanceDocument maintenanceDocument= ((MaintenanceDocumentForm) viewModel).getDocument();
27          AlertDocument alertDocument=(AlertDocument)maintenanceDocument.getDocumentDataObject();
28          List<KeyValue> options = new ArrayList<KeyValue>();
29          Class alertDocumentClass = null;
30          try {
31              alertDocumentClass = Class.forName(alertDocument.getDocumentClassName());
32          } catch (ClassNotFoundException e) {
33              e.printStackTrace();
34          }
35          Field[] declaredFields =alertDocumentClass.getDeclaredFields();
36          for(Field field:declaredFields){
37              Annotation[] anotations=field.getDeclaredAnnotations();
38              for(Annotation anotation:anotations){
39                  if(anotation instanceof AlertField){
40                      String sdd=field.getType().toString().replace(".", "-");
41                      String[] value = sdd.split("-");
42                      String lastOne = value[value.length-1];
43                      options.add(new ConcreteKeyValue(lastOne, lastOne));
44                  }
45              }
46          }
47  
48  
49  
50  
51          return options;*/
52  
53          MaintenanceDocument maintenanceDocument= ((MaintenanceDocumentForm) viewModel).getDocument();
54          AlertEvent alertEvent=(AlertEvent)maintenanceDocument.getDocumentDataObject();
55          List<KeyValue> options = new ArrayList<KeyValue>();
56          Class alertDocumentClass = null;
57          try {
58              alertDocumentClass = Class.forName(alertEvent.getAlertDocumentClassName());
59          } catch (ClassNotFoundException e) {
60              e.printStackTrace();
61          }
62          Field[] declaredFields =alertDocumentClass.getDeclaredFields();
63          for(Field field:declaredFields){
64              Annotation[] annotations=field.getDeclaredAnnotations();
65              for(Annotation annotation:annotations){
66                  if(annotation instanceof AlertField){
67                      String sdd=field.getType().toString().replace(".", "-");
68                      String[] value = sdd.split("-");
69                      String lastOne = value[value.length-1];
70                      options.add(new ConcreteKeyValue(lastOne, lastOne));
71                  }
72              }
73          }
74  
75  
76  
77  
78          return options;
79      }
80  }