continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From batkin...@apache.org
Subject svn commit: r1677506 - in /continuum/trunk/continuum-webapp/src/main: java/org/apache/continuum/web/action/ViewBuildsReportAction.java resources/localization/Continuum.properties
Date Mon, 04 May 2015 01:42:34 GMT
Author: batkinson
Date: Mon May  4 01:42:34 2015
New Revision: 1677506

URL: http://svn.apache.org/r1677506
Log:
Simplified report action result state handling and made them localizable.

Modified:
    continuum/trunk/continuum-webapp/src/main/java/org/apache/continuum/web/action/ViewBuildsReportAction.java
    continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties

Modified: continuum/trunk/continuum-webapp/src/main/java/org/apache/continuum/web/action/ViewBuildsReportAction.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/java/org/apache/continuum/web/action/ViewBuildsReportAction.java?rev=1677506&r1=1677505&r2=1677506&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/java/org/apache/continuum/web/action/ViewBuildsReportAction.java
(original)
+++ continuum/trunk/continuum-webapp/src/main/java/org/apache/continuum/web/action/ViewBuildsReportAction.java
Mon May  4 01:42:34 2015
@@ -40,6 +40,7 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -63,6 +64,59 @@ public class ViewBuildsReportAction
         new String[] { "MM/dd/yy", "MM/dd/yyyy", "MMMMM/dd/yyyy", "MMMMM/dd/yy", "dd MMMMM
yyyy", "dd/MM/yy",
             "dd/MM/yyyy", "yyyy/MM/dd", "yyyy-MM-dd", "yyyy-dd-MM", "MM-dd-yyyy", "MM-dd-yy"
};
 
+    /**
+     * Encapsulates constants relevant for build results and makes them localizable.
+     */
+    public enum ResultState
+    {
+        OK( ContinuumProjectState.OK, "projectBuilds.report.resultOk" ),
+        FAILED( ContinuumProjectState.FAILED, "projectBuilds.report.resultFailed" ),
+        ERROR( ContinuumProjectState.ERROR, "projectBuilds.report.resultError" ),
+        BUILDING( ContinuumProjectState.BUILDING, "projectBuilds.report.resultBuilding" ),
+        CANCELLED( ContinuumProjectState.CANCELLED, "projectBuilds.report.resultCanceled"
);
+
+        private static final Map<Integer, ResultState> dataMap;
+
+        static
+        {
+            dataMap = new HashMap<Integer, ResultState>();
+            for ( ResultState val : ResultState.values() )
+            {
+                dataMap.put( val.dataId, val );
+            }
+        }
+
+        private int dataId;
+
+        private String textKey;
+
+        ResultState( int dataId, String textKey )
+        {
+            this.dataId = dataId;
+            this.textKey = textKey;
+        }
+
+        public int getDataId()
+        {
+            return dataId;
+        }
+
+        public String getTextKey()
+        {
+            return textKey;
+        }
+
+        public static ResultState fromId( int state )
+        {
+            return dataMap.get( state );
+        }
+
+        public static boolean knownState( int state )
+        {
+            return dataMap.containsKey( state );
+        }
+    }
+
     private int buildStatus;
 
     private String triggeredBy = "";
@@ -112,13 +166,13 @@ public class ViewBuildsReportAction
     {
         super.prepare();
 
+        // Populate the state drop downs
         buildStatuses = new LinkedHashMap<Integer, String>();
         buildStatuses.put( 0, "ALL" );
-        buildStatuses.put( ContinuumProjectState.OK, "Ok" );
-        buildStatuses.put( ContinuumProjectState.FAILED, "Failed" );
-        buildStatuses.put( ContinuumProjectState.ERROR, "Error" );
-        buildStatuses.put( ContinuumProjectState.BUILDING, "Building" );
-        buildStatuses.put( ContinuumProjectState.CANCELLED, "Canceled" );
+        for ( ResultState state : ResultState.values() )
+        {
+            buildStatuses.put( state.getDataId(), getText( state.getTextKey() ) );
+        }
 
         projectGroups = new LinkedHashMap<Integer, String>();
         projectGroups.put( 0, "ALL" );
@@ -327,34 +381,10 @@ public class ViewBuildsReportAction
                         Project project = result.getProject();
                         ProjectGroup projectGroup = project.getProjectGroup();
 
-                        // Decode status into human-readable form
-                        String state;
-                        switch ( result.getState() )
-                        {
-                            case 2:
-                                state = "Ok";
-                                break;
-                            case 3:
-                                state = "Failed";
-                                break;
-                            case 4:
-                                state = "Error";
-                                break;
-                            case 6:
-                                state = "Building";
-                                break;
-                            case 7:
-                                state = "Checking Out";
-                                break;
-                            case 8:
-                                state = "Updating";
-                                break;
-                            case 11:
-                                state = "Canceled";
-                                break;
-                            default:
-                                state = "";
-                        }
+                        int resultState = result.getState();
+                        String stateName = ResultState.knownState( resultState ) ?
+                            getText( ResultState.fromId( resultState ).getTextKey() ) :
+                            getText( "projectBuilds.report.resultUnknown" );
 
                         String buildTime = dateTimeFormat.format( new Date( result.getStartTime()
) );
                         long buildDuration = ( result.getEndTime() - result.getStartTime()
) / 1000;
@@ -367,7 +397,7 @@ public class ViewBuildsReportAction
                                                               buildTime,
                                                               buildDuration,
                                                               result.getUsername(),
-                                                              state );
+                                                              stateName );
                         output.append( formattedLine );
 
                         if ( exported >= MAX_EXPORT_SIZE )

Modified: continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties?rev=1677506&r1=1677505&r2=1677506&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
(original)
+++ continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
Mon May  4 01:42:34 2015
@@ -1333,6 +1333,12 @@ projectBuilds.report.invalidPage=Specifi
 projectBuilds.report.exportIOError=There was an input/output error during export: {0}
 projectBuilds.report.badDates=Failed to parse date(s): {0}
 projectBuilds.report.endBeforeStartDate=Invalid date range: start date must be earlier than
the end date.
+projectBuilds.report.resultOk=Ok
+projectBuilds.report.resultFailed=Failed
+projectBuilds.report.resultError=Error
+projectBuilds.report.resultBuilding=Building
+projectBuilds.report.resultCanceled=Canceled
+projectBuilds.report.resultUnknown=Unknown
 
 build.project.success=successfully queued build
 build.projects.success=successfully queued builds



Mime
View raw message