Coverage Report - ar.com.fdvs.dj.domain.DJCrosstabMeasure
 
Classes in this File Line Coverage Branch Coverage Complexity
DJCrosstabMeasure
77%
60/77
87%
7/8
1.154
 
 1  
 /*
 2  
  * DynamicJasper: A library for creating reports dynamically by specifying
 3  
  * columns, groups, styles, etc. at runtime. It also saves a lot of development
 4  
  * time in many cases! (http://sourceforge.net/projects/dynamicjasper)
 5  
  *
 6  
  * Copyright (C) 2008  FDV Solutions (http://www.fdvsolutions.com)
 7  
  *
 8  
  * This library is free software; you can redistribute it and/or
 9  
  * modify it under the terms of the GNU Lesser General Public
 10  
  *
 11  
  * License as published by the Free Software Foundation; either
 12  
  *
 13  
  * version 2.1 of the License, or (at your option) any later version.
 14  
  *
 15  
  * This library is distributed in the hope that it will be useful,
 16  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17  
  *
 18  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19  
  *
 20  
  * Lesser General Public License for more details.
 21  
  *
 22  
  * You should have received a copy of the GNU Lesser General Public
 23  
  * License along with this library; if not, write to the Free Software
 24  
  *
 25  
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 26  
  *
 27  
  *
 28  
  */
 29  
 
 30  
 package ar.com.fdvs.dj.domain;
 31  
 
 32  
 import java.util.*;
 33  
 
 34  
 import org.apache.commons.collections.CollectionUtils;
 35  
 import org.apache.commons.collections.Transformer;
 36  
 import org.apache.commons.logging.Log;
 37  
 import org.apache.commons.logging.LogFactory;
 38  
 
 39  
 import ar.com.fdvs.dj.domain.entities.Entity;
 40  
 import ar.com.fdvs.dj.util.ExpressionUtils;
 41  
 
 42  
 
 43  
 public class DJCrosstabMeasure extends DJBaseElement {
 44  
         /**
 45  
          * Logger for this class
 46  
          */
 47  1
         private static final Log logger = LogFactory.getLog(DJCrosstabMeasure.class);
 48  
 
 49  
         /**
 50  
          * Logger for this class
 51  
          */
 52  
 
 53  
         private static final long serialVersionUID = Entity.SERIAL_VERSION_UID;
 54  
         
 55  
         private ColumnProperty property;
 56  
         private DJCalculation operation;
 57  
         private String title;
 58  14
         private List conditionalStyles = new ArrayList();
 59  
         private DJValueFormatter valueFormatter;
 60  
         private DJCRosstabMeasurePrecalculatedTotalProvider precalculatedTotalProvider;
 61  14
         private Boolean isPercentage = Boolean.FALSE;
 62  14
         private Boolean visible = Boolean.TRUE;
 63  
 
 64  
         private Style style;
 65  
         
 66  
         private DJHyperLink link;
 67  
 
 68  
         public Style getStyle() {
 69  22
                 return style;
 70  
         }
 71  
 
 72  
         public void setStyle(Style style) {
 73  11
                 this.style = style;
 74  11
         }
 75  
 
 76  
         public List getConditionalStyles() {
 77  103
                 return conditionalStyles;
 78  
         }
 79  
 
 80  
         public void setConditionalStyles(List conditionalStyles) {
 81  0
                 this.conditionalStyles = conditionalStyles;
 82  0
         }
 83  
         
 84  
         public DJCrosstabMeasure(String propertyName, String className, DJCalculation operation, String title) {
 85  11
                 super();
 86  11
                 this.property = new ColumnProperty(propertyName, className);
 87  11
                 this.operation = operation;
 88  11
                 this.title = title;
 89  11
         }
 90  
 
 91  
         public DJCrosstabMeasure(ColumnProperty measure, DJCalculation operation, String title) {
 92  0
                 super();
 93  0
                 this.property = measure;
 94  0
                 this.operation = operation;
 95  0
                 this.title = title;
 96  0
         }
 97  
 
 98  
         public DJCrosstabMeasure() {
 99  3
                 super();
 100  3
         }
 101  
 
 102  
         public ColumnProperty getProperty() {
 103  378
                 return property;
 104  
         }
 105  
         public void setProperty(ColumnProperty measure) {
 106  0
                 this.property = measure;
 107  0
         }
 108  
         public DJCalculation getOperation() {
 109  20
                 return operation;
 110  
         }
 111  
         public void setOperation(DJCalculation operation) {
 112  0
                 this.operation = operation;
 113  0
         }
 114  
         public String getTitle() {
 115  0
                 return title;
 116  
         }
 117  
         public void setTitle(String title) {
 118  0
                 this.title = title;
 119  0
         }
 120  
 
 121  
         public DJHyperLink getLink() {
 122  85
                 return link;
 123  
         }
 124  
 
 125  
         public void setLink(DJHyperLink link) {
 126  1
                 this.link = link;
 127  1
         }
 128  
 
 129  
         public DJValueFormatter getValueFormatter() {
 130  157
                 return valueFormatter;
 131  
         }
 132  
 
 133  
         public void setValueFormatter(DJValueFormatter valueFormatter) {
 134  5
                 this.valueFormatter = valueFormatter;
 135  5
         }
 136  
 
 137  
         public String getTextForValueFormatterExpression(String variableName, List<DJCrosstabMeasure> measures) {
 138  19
        String stringExpression = null;
 139  19
         String fieldsMap = ExpressionUtils.getTextForFieldsFromScriptlet();
 140  19
         String parametersMap = ExpressionUtils.getTextForParametersFromScriptlet();
 141  19
         String variablesMap = ExpressionUtils.getTextForVariablesFromScriptlet();
 142  19
         if (this.getValueFormatter() instanceof DjBaseMMValueFormatter){
 143  
 
 144  9
             DjBaseMMValueFormatter formatter = DjBaseMMValueFormatter.class.cast(this.getValueFormatter());
 145  9
             String[] propertyMeasures = new String[measures.size()];
 146  
 
 147  9
             int i = 0;
 148  9
             for (DJCrosstabMeasure measure : measures) {
 149  18
                 propertyMeasures[i] = measure.getProperty().getProperty();
 150  18
                 i++;
 151  
             }
 152  
 
 153  9
             formatter.setPropertyMeasures(propertyMeasures);
 154  
 
 155  9
             String rowValuesExp = "new Object[]{";
 156  9
             int measureIdx=0;
 157  27
             for (Iterator iterator = measures.iterator(); iterator.hasNext(); measureIdx++) {
 158  18
                 DJCrosstabMeasure djmeasure = (DJCrosstabMeasure) iterator.next();
 159  
 
 160  18
                 if (djmeasure.getProperty()== null){
 161  0
                     continue;
 162  
                 }
 163  
 
 164  18
                 rowValuesExp += "$V{" +djmeasure.getMeasureIdentifier(measureIdx) +"}";
 165  18
                 rowValuesExp += ", ";
 166  
             }
 167  
 
 168  
             //chop the last comma
 169  9
             rowValuesExp = rowValuesExp.substring(0,rowValuesExp.length()-2);
 170  9
             rowValuesExp += "}";
 171  9
             stringExpression = "((("+DjBaseMMValueFormatter.class.getName()+")$P{crosstab-measure__"+variableName+"_vf}).evaluate( "
 172  
                         + rowValuesExp + ", " + fieldsMap +", " + variablesMap + ", " + parametersMap +" ))";
 173  9
        }
 174  
         else {
 175  
 
 176  10
              stringExpression = "((("+DJValueFormatter.class.getName()+")$P{crosstab-measure__"+variableName+"_vf}).evaluate( "
 177  
                     + "$V{"+variableName+"}, " + fieldsMap +", " + variablesMap + ", " + parametersMap +" ))";
 178  
         }
 179  
 
 180  19
         logger.debug("Expression for crosstab DJValueFormatter = " + stringExpression);
 181  
 
 182  19
                 return stringExpression;
 183  
         }
 184  
 
 185  
     public String getMeasureIdentifier(int idx) {
 186  99
         String measurePrefix = this.getMeasurePrefix(idx);
 187  99
         String measureProperty = measurePrefix + this.getProperty().getProperty();
 188  99
         return measureProperty;
 189  
     }
 190  
 
 191  
     public String getMeasurePrefix(int idx) {
 192  180
         return "idx" + idx + "_";
 193  
     }
 194  
 
 195  
         public DJCRosstabMeasurePrecalculatedTotalProvider getPrecalculatedTotalProvider() {
 196  83
                 return precalculatedTotalProvider;
 197  
         }
 198  
 
 199  
         public void setPrecalculatedTotalProvider(
 200  
                         DJCRosstabMeasurePrecalculatedTotalProvider precalculatedTotalProvider) {
 201  2
                 this.precalculatedTotalProvider = precalculatedTotalProvider;
 202  2
         }
 203  
 
 204  
         public Boolean getIsPercentage() {
 205  11
                 return isPercentage;
 206  
         }
 207  
 
 208  
         public void setIsPercentage(Boolean isPercentage) {
 209  0
                 this.isPercentage = isPercentage;
 210  0
         }
 211  
 
 212  
 
 213  
     public Boolean getVisible() {
 214  283
         return visible;
 215  
     }
 216  
 
 217  
     public void setVisible(Boolean visible) {
 218  3
         this.visible = visible;
 219  3
     }
 220  
 }