← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18506: Codestyle

 

------------------------------------------------------------
revno: 18506
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-03-06 12:35:01 +0100
message:
  Codestyle
modified:
  dhis-2/dhis-services/dhis-service-analytics/pom.xml
  dhis-2/dhis-services/dhis-service-core/pom.xml
  dhis-2/dhis-services/dhis-service-datamart-default/pom.xml
  dhis-2/dhis-services/dhis-service-reporting/pom.xml
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/pom.xml'
--- dhis-2/dhis-services/dhis-service-analytics/pom.xml	2015-03-05 18:41:52 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/pom.xml	2015-03-06 11:35:01 +0000
@@ -37,10 +37,6 @@
     <!-- Other -->
     
     <dependency>
-      <groupId>org.scijava</groupId>
-      <artifactId>jep</artifactId>
-    </dependency>
-    <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
     </dependency>

=== modified file 'dhis-2/dhis-services/dhis-service-core/pom.xml'
--- dhis-2/dhis-services/dhis-service-core/pom.xml	2015-03-05 18:41:52 +0000
+++ dhis-2/dhis-services/dhis-service-core/pom.xml	2015-03-06 11:35:01 +0000
@@ -54,10 +54,6 @@
     <!-- Other -->
 
     <dependency>
-      <groupId>org.scijava</groupId>
-      <artifactId>jep</artifactId>
-    </dependency>
-    <dependency>
       <groupId>commons-codec</groupId>
       <artifactId>commons-codec</artifactId>
     </dependency>

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/pom.xml'
--- dhis-2/dhis-services/dhis-service-datamart-default/pom.xml	2015-03-05 18:41:52 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/pom.xml	2015-03-06 11:35:01 +0000
@@ -29,10 +29,6 @@
     <!-- Other -->
     
     <dependency>
-      <groupId>org.scijava</groupId>
-      <artifactId>jep</artifactId>
-    </dependency>
-    <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
     </dependency>

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/pom.xml'
--- dhis-2/dhis-services/dhis-service-reporting/pom.xml	2015-03-05 18:41:52 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/pom.xml	2015-03-06 11:35:01 +0000
@@ -87,10 +87,6 @@
     <!-- Other -->
     
     <dependency>
-      <groupId>org.scijava</groupId>
-      <artifactId>jep</artifactId>
-    </dependency>
-    <dependency>
       <groupId>commons-math</groupId>
       <artifactId>commons-math</artifactId>
     </dependency>

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java	2015-02-16 17:57:07 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java	2015-03-06 11:35:01 +0000
@@ -50,14 +50,11 @@
 import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService;
 import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValue;
 import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueService;
-import org.nfunk.jep.JEP;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
  * @author Chau Thu Tran
- * @version $ DefaultProgramIndicatorService.java Apr 16, 2013 1:29:00 PM $
  */
-
 @Transactional
 public class DefaultProgramIndicatorService
     implements ProgramIndicatorService
@@ -114,7 +111,7 @@
     {
         this.attributeValueService = attributeValueService;
     }
-    
+
     private ConstantService constantService;
 
     public void setConstantService( ConstantService constantService )
@@ -223,15 +220,16 @@
     {
         Map<String, String> result = new HashMap<>();
 
-        Collection<ProgramIndicator> programIndicators = programIndicatorStore.getByProgram( programInstance
-            .getProgram() );
+        Collection<ProgramIndicator> programIndicators = programIndicatorStore.getByProgram( programInstance.getProgram() );
 
         for ( ProgramIndicator programIndicator : programIndicators )
         {
             String value = getProgramIndicatorValue( programInstance, programIndicator );
-            if( value != null )
+            
+            if ( value != null )
             {
-                result.put( programIndicator.getDisplayName(), getProgramIndicatorValue( programInstance, programIndicator ) );
+                result.put( programIndicator.getDisplayName(),
+                    getProgramIndicatorValue( programInstance, programIndicator ) );
             }
         }
 
@@ -246,6 +244,7 @@
         Pattern patternCondition = Pattern.compile( ProgramIndicator.regExp );
 
         Matcher matcher = patternCondition.matcher( expression );
+        
         while ( matcher.find() )
         {
             String key = matcher.group( 1 );
@@ -261,28 +260,32 @@
                 if ( programStage != null && dataElement != null )
                 {
                     String programStageName = programStage.getDisplayName();
-               
+
                     String dataelementName = dataElement.getDisplayName();
-               
+
                     matcher.appendReplacement( description, ProgramIndicator.KEY_DATAELEMENT + "{" + programStageName
-                    + ProgramIndicator.SEPARATOR_ID + dataelementName + "}" );
+                        + ProgramIndicator.SEPARATOR_ID + dataelementName + "}" );
                 }
             }
-            
+
             else if ( key.equals( ProgramIndicator.KEY_ATTRIBUTE ) )
             {
                 TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute( uid1 );
+                
                 if ( attribute != null )
                 {
-                    matcher.appendReplacement( description, ProgramIndicator.KEY_ATTRIBUTE + "{" + attribute.getDisplayName() + "}" );    
+                    matcher.appendReplacement( description,
+                        ProgramIndicator.KEY_ATTRIBUTE + "{" + attribute.getDisplayName() + "}" );
                 }
             }
             else if ( key.equals( ProgramIndicator.KEY_CONSTANT ) )
             {
                 Constant constant = constantService.getConstant( uid1 );
+                
                 if ( constant != null )
                 {
-                    matcher.appendReplacement( description, ProgramIndicator.KEY_CONSTANT + "{" + constant.getDisplayName() + "}" );
+                    matcher.appendReplacement( description,
+                        ProgramIndicator.KEY_CONSTANT + "{" + constant.getDisplayName() + "}" );
                 }
             }
         }
@@ -290,9 +293,9 @@
         matcher.appendTail( description );
 
         return description.toString();
-        
+
     }
-    
+
     public String expressionIsValid( String expression )
     {
         StringBuffer description = new StringBuffer();
@@ -300,6 +303,7 @@
         Pattern patternCondition = Pattern.compile( ProgramIndicator.regExp );
 
         Matcher matcher = patternCondition.matcher( expression );
+        
         while ( matcher.find() )
         {
             String key = matcher.group( 1 );
@@ -314,20 +318,21 @@
 
                 if ( programStage != null && dataElement != null )
                 {
-                    matcher.appendReplacement( description, "1" );
+                    matcher.appendReplacement( description, String.valueOf( 1 ) );
                 }
                 else
                 {
                     return ProgramIndicator.EXPRESSION_NOT_WELL_FORMED;
                 }
             }
-            
+
             else if ( key.equals( ProgramIndicator.KEY_ATTRIBUTE ) )
             {
                 TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute( uid1 );
+                
                 if ( attribute != null )
                 {
-                    matcher.appendReplacement( description, "1" );
+                    matcher.appendReplacement( description, String.valueOf( 1 ) );
                 }
                 else
                 {
@@ -337,9 +342,10 @@
             else if ( key.equals( ProgramIndicator.KEY_CONSTANT ) )
             {
                 Constant constant = constantService.getConstant( uid1 );
+                
                 if ( constant != null )
                 {
-                    matcher.appendReplacement( description, constant.getValue() + "" );
+                    matcher.appendReplacement( description, String.valueOf( constant.getValue() ) );
                 }
                 else
                 {
@@ -348,8 +354,8 @@
             }
             else if ( key.equals( ProgramIndicator.KEY_PROGRAM_VARIABLE ) )
             {
-               matcher.appendReplacement( description, 0 + "" );
-          }
+                matcher.appendReplacement( description, String.valueOf( 0 ) );
+            }
         }
 
         matcher.appendTail( description );
@@ -357,7 +363,7 @@
         // ---------------------------------------------------------------------
         // Well-formed expression
         // ---------------------------------------------------------------------
-        
+
         if ( MathUtils.expressionHasErrors( description.toString() ) )
         {
             return ProgramIndicator.EXPRESSION_NOT_WELL_FORMED;
@@ -365,7 +371,6 @@
 
         return ProgramIndicator.VALID;
     }
-    
 
     // -------------------------------------------------------------------------
     // Supportive methods
@@ -379,7 +384,7 @@
 
         Pattern pattern = Pattern.compile( ProgramIndicator.regExp );
         Matcher matcher = pattern.matcher( expression );
-        
+
         while ( matcher.find() )
         {
             String key = matcher.group( 1 );
@@ -390,28 +395,28 @@
                 String uid2 = matcher.group( 3 );
                 ProgramStage programStage = programStageService.getProgramStage( uid1 );
                 DataElement dataElement = dataElementService.getDataElement( uid2 );
-                
+
                 if ( programStage != null && dataElement != null )
                 {
                     ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(
                         programInstance, programStage );
-                    
-                    TrackedEntityDataValue dataValue = dataValueService.getTrackedEntityDataValue( programStageInstance,
-                        dataElement );
-    
+
+                    TrackedEntityDataValue dataValue = dataValueService.getTrackedEntityDataValue(
+                        programStageInstance, dataElement );
+
                     if ( dataValue == null )
                     {
                         return null;
                     }
-    
+
                     value = dataValue.getValue();
-    
+
                     if ( valueType.equals( ProgramIndicator.VALUE_TYPE_INT )
                         && (dataElement == null || dataElement.getType().equals( DataElement.VALUE_TYPE_DATE )) )
                     {
                         value = DateUtils.daysBetween( new Date(), DateUtils.getDefaultDate( value ) ) + " ";
                     }
-    
+
                     matcher.appendReplacement( description, value );
                 }
                 else
@@ -422,11 +427,13 @@
             else if ( key.equals( ProgramIndicator.KEY_ATTRIBUTE ) )
             {
                 TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute( uid1 );
+                
                 if ( attribute != null )
                 {
-                    TrackedEntityAttributeValue attrValue = attributeValueService.getTrackedEntityAttributeValue( programInstance.getEntityInstance(), attribute );
+                    TrackedEntityAttributeValue attrValue = attributeValueService.getTrackedEntityAttributeValue(
+                        programInstance.getEntityInstance(), attribute );
 
-                    if( attrValue != null )
+                    if ( attrValue != null )
                     {
                         matcher.appendReplacement( description, attrValue.getValue() );
                     }
@@ -443,9 +450,10 @@
             else if ( key.equals( ProgramIndicator.KEY_CONSTANT ) )
             {
                 Constant constant = constantService.getConstant( uid1 );
+                
                 if ( constant != null )
                 {
-                    matcher.appendReplacement( description, constant.getValue() + "" );
+                    matcher.appendReplacement( description, String.valueOf( constant.getValue() ) );
                 }
                 else
                 {
@@ -454,40 +462,32 @@
             }
             else if ( key.equals( ProgramIndicator.KEY_PROGRAM_VARIABLE ) )
             {
-                  Date currentDate = new Date();
-                  Date date = null;
-                  if( uid1.equals( ProgramIndicator.ENROLLEMENT_DATE ))
-                  {
-                      date = programInstance.getEnrollmentDate();
-                  }
-                  else if( uid1.equals( ProgramIndicator.INCIDENT_DATE ))
-                  {
-                      date = programInstance.getDateOfIncident();
-                  }
-                  else if( uid1.equals( ProgramIndicator.CURRENT_DATE ))
-                  {
-                      date = programInstance.getDateOfIncident();
-                  }
-                  
-                  if ( date != null )
-                  { 
-                      matcher.appendReplacement( description, DateUtils.daysBetween( date, currentDate ) + "" );
-                  }
+                Date currentDate = new Date();
+                Date date = null;
+                
+                if ( uid1.equals( ProgramIndicator.ENROLLEMENT_DATE ) )
+                {
+                    date = programInstance.getEnrollmentDate();
+                }
+                else if ( uid1.equals( ProgramIndicator.INCIDENT_DATE ) )
+                {
+                    date = programInstance.getDateOfIncident();
+                }
+                else if ( uid1.equals( ProgramIndicator.CURRENT_DATE ) )
+                {
+                    date = programInstance.getDateOfIncident();
+                }
+
+                if ( date != null )
+                {
+                    matcher.appendReplacement( description, DateUtils.daysBetween( date, currentDate ) + "" );
+                }
             }
 
         }
+
+        matcher.appendTail( description );
         
-        matcher.appendTail( description );
-        try
-        {
-            final JEP parser = new JEP();
-            parser.parseExpression( description.toString() );
-    
-            return parser.getValue();
-        }
-        catch( Exception ex )
-        {
-            return null;
-        }
+        return MathUtils.calculateExpression( description.toString() );
     }
 }