| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| KSCustomDataSource |
|
| 6.333333333333333;6.333 |
| 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 | ||
| 16 | /** | |
| 17 | * This is a custom data source class to convert a datamodel to a Jasper report data source object. | |
| 18 | * | |
| 19 | * @author Kuali Rice Team (kuali-rice@googlegroups.com) | |
| 20 | */ | |
| 21 | public class KSCustomDataSource implements JRDataSource { | |
| 22 | ||
| 23 | private Iterator<Property> iterator; | |
| 24 | ||
| 25 | private Property property; | |
| 26 | ||
| 27 | private DateFormat format; | |
| 28 | ||
| 29 | /** | |
| 30 | * | |
| 31 | */ | |
| 32 | 12 | public KSCustomDataSource(final Iterator<Property> source) { |
| 33 | 12 | this.iterator = source; |
| 34 | 12 | this.format = new SimpleDateFormat("yyyy-MM-dd"); |
| 35 | 12 | } |
| 36 | ||
| 37 | /** | |
| 38 | * | |
| 39 | */ | |
| 40 | public boolean next() throws JRException { | |
| 41 | try { | |
| 42 | 66 | property = (Property) iterator.next(); |
| 43 | 60 | if (("metaInfo".equals(property.getKey().toString())) || ("id".equals(property.getKey().toString())) || ("_runtimeData".equals(property.getKey().toString()))) { |
| 44 | 0 | return this.next(); |
| 45 | } | |
| 46 | 6 | } catch (NoSuchElementException e) { |
| 47 | 6 | return false; |
| 48 | 60 | } |
| 49 | 60 | return true; |
| 50 | } | |
| 51 | ||
| 52 | /** | |
| 53 | * | |
| 54 | */ | |
| 55 | public Object getFieldValue(JRField field) throws JRException { | |
| 56 | 519 | Object value = null; |
| 57 | ||
| 58 | 519 | String fieldName = field.getName(); |
| 59 | 519 | if ("key".equals(fieldName)) { |
| 60 | 57 | value = property.getKey().toString(); |
| 61 | } else { | |
| 62 | 462 | if (property.getValueType().equals(Data.class)) { |
| 63 | 72 | if ("sub".equals(fieldName)) { |
| 64 | 9 | value = new Boolean(true); |
| 65 | 63 | } else if ("value".equals(fieldName)) { |
| 66 | 9 | value = null; |
| 67 | 54 | } else if ("subset".equals(fieldName)) { |
| 68 | 9 | value = new KSCustomDataSource(((Data) property.getValue()).iterator()); |
| 69 | } | |
| 70 | } else { | |
| 71 | 390 | if ("sub".equals(fieldName)) { |
| 72 | 48 | value = new Boolean(false); |
| 73 | 342 | } else if ("value".equals(fieldName)) { |
| 74 | 51 | if (property.getValue() instanceof Date) { |
| 75 | 0 | value = format.format((Date) property.getValue()); |
| 76 | } else { | |
| 77 | 51 | if (property.getValue() != null) { |
| 78 | 48 | value = property.getValue().toString(); |
| 79 | } | |
| 80 | } | |
| 81 | 291 | } else if ("subset".equals(fieldName)) { |
| 82 | 48 | value = null; |
| 83 | } | |
| 84 | } | |
| 85 | } | |
| 86 | 519 | return value; |
| 87 | } | |
| 88 | ||
| 89 | } |