| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| KSCustomDataSource | 
 | 
 | 5.0;5 | ||||
| KSCustomDataSource$1 | 
 | 
 | 5.0;5 | 
| 1 |  package org.kuali.student.common.ui.server.screenreport.jasper; | |
| 2 | ||
| 3 |  import java.text.DateFormat; | |
| 4 |  import java.text.SimpleDateFormat; | |
| 5 |  import java.util.Date; | |
| 6 |  import java.util.Iterator; | |
| 7 |  import java.util.NoSuchElementException; | |
| 8 | ||
| 9 |  import net.sf.jasperreports.engine.JRDataSource; | |
| 10 |  import net.sf.jasperreports.engine.JRException; | |
| 11 |  import net.sf.jasperreports.engine.JRField; | |
| 12 | ||
| 13 |  import org.kuali.student.common.assembly.data.Data; | |
| 14 |  import org.kuali.student.common.assembly.data.Data.Property; | |
| 15 |  import org.kuali.student.common.util.DateFormatThread; | |
| 16 | ||
| 17 |  /** | |
| 18 |   * This is a custom data source class to convert a datamodel to a Jasper report data source object. | |
| 19 |   *  | |
| 20 |   * @author Kuali Rice Team (kuali-rice@googlegroups.com) | |
| 21 |   */ | |
| 22 | public class KSCustomDataSource implements JRDataSource { | |
| 23 | ||
| 24 |      private Iterator<Property> iterator; | |
| 25 | ||
| 26 |      private Property property; | |
| 27 | ||
| 28 | 1 | private static ThreadLocal<DateFormat> df = new ThreadLocal<DateFormat>() { | 
| 29 |                  protected DateFormat initialValue() { | |
| 30 | 0 |                          return new SimpleDateFormat("yyyy-MM-dd"); | 
| 31 | } | |
| 32 | }; | |
| 33 | ||
| 34 |      /** | |
| 35 |           * | |
| 36 |           */ | |
| 37 | 12 | public KSCustomDataSource(final Iterator<Property> source) { | 
| 38 | 12 |          this.iterator = source; | 
| 39 | 12 | } | 
| 40 | ||
| 41 |      /** | |
| 42 |           * | |
| 43 |           */ | |
| 44 | public boolean next() throws JRException { | |
| 45 |          try { | |
| 46 | 66 | property = (Property) iterator.next(); | 
| 47 | 60 |              if (("metaInfo".equals(property.getKey().toString())) || ("id".equals(property.getKey().toString())) || ("_runtimeData".equals(property.getKey().toString()))) { | 
| 48 | 0 |                  return this.next(); | 
| 49 | } | |
| 50 | 6 |          } catch (NoSuchElementException e) { | 
| 51 | 6 | return false; | 
| 52 | 60 | } | 
| 53 | 60 | return true; | 
| 54 | } | |
| 55 | ||
| 56 |      /** | |
| 57 |           * | |
| 58 |           */ | |
| 59 | public Object getFieldValue(JRField field) throws JRException { | |
| 60 | 519 |          Object value = null; | 
| 61 | ||
| 62 | 519 | String fieldName = field.getName(); | 
| 63 | 519 | if ("key".equals(fieldName)) { | 
| 64 | 57 | value = property.getKey().toString(); | 
| 65 |          } else { | |
| 66 | 462 | if (property.getValueType().equals(Data.class)) { | 
| 67 | 72 | if ("sub".equals(fieldName)) { | 
| 68 | 9 | value = new Boolean(true); | 
| 69 | 63 | } else if ("value".equals(fieldName)) { | 
| 70 | 9 |                      value = null; | 
| 71 | 54 | } else if ("subset".equals(fieldName)) { | 
| 72 | 9 |                      value = new KSCustomDataSource(((Data) property.getValue()).iterator()); | 
| 73 | } | |
| 74 |              } else { | |
| 75 | 390 | if ("sub".equals(fieldName)) { | 
| 76 | 48 | value = new Boolean(false); | 
| 77 | 342 | } else if ("value".equals(fieldName)) { | 
| 78 | 51 |                      if (property.getValue() instanceof Date) { | 
| 79 | 0 |                          value = df.get().format((Date) property.getValue()); | 
| 80 |                      } else { | |
| 81 | 51 | if (property.getValue() != null) { | 
| 82 | 48 | value = property.getValue().toString(); | 
| 83 | } | |
| 84 | } | |
| 85 | 291 | } else if ("subset".equals(fieldName)) { | 
| 86 | 48 |                      value = null; | 
| 87 | } | |
| 88 | } | |
| 89 | } | |
| 90 | 519 |          return value; | 
| 91 | } | |
| 92 | ||
| 93 | } |