Scarab commit: svn commit: r10991 - trunk/src/java/org/tigris/scarab: tools workflow

[email protected] Fri, 16 Apr 2010 13:01:52 -0700 (PDT)
Newsgroups gmane.comp.java.scarab.cvs
Message-ID <[email protected]>
Author: dabbous
Date: 2010-04-16 13:01:52-0700
New Revision: 10991

Added:
   trunk/src/java/org/tigris/scarab/tools/Environment.java
Modified:
   trunk/src/java/org/tigris/scarab/tools/ScarabGlobalTool.java
   trunk/src/java/org/tigris/scarab/tools/ScarabRequestTool.java
   trunk/src/java/org/tigris/scarab/workflow/IssueState.java

Log:
Software strctural maintenance. Started a new Tool class as an API to the Runtime Environment.
This is mainly implemented by the TurbineConfiguration package. But several classes use duplicate
code sequences. As i needed it in yet another package, i decided to refactor the environment
into an API. When this is finished, the Scarab Kernel should no longer show dependencies to 
the Turbine Configuration package.

Note: It may be a good idea to add more such API classes by time to isolate the Scarab kernel
from the turbine and torque packages.

Added: trunk/src/java/org/tigris/scarab/tools/Environment.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/tools/Environment.java?view=markup&pathrev=10991
==============================================================================
--- (empty file)
+++ trunk/src/java/org/tigris/scarab/tools/Environment.java	2010-04-16 13:01:52-0700
@@ -0,0 +1,73 @@
+package org.tigris.scarab.tools;
+
+/* ================================================================
+ * Copyright (c) 2010 CollabNet.  All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement: "This product includes
+ * software developed by CollabNet (http://www.collab.net/)."
+ * Alternately, this acknowlegement may appear in the software itself, if
+ * and wherever such third-party acknowlegements normally appear.
+ * 
+ * 4. The hosted project names must not be used to endorse or promote
+ * products derived from this software without prior written
+ * permission. For written permission, please contact [email protected].
+ * 
+ * 5. Products derived from this software may not use the "Tigris" name
+ * nor may "Tigris" appear in their names without prior written
+ * permission of CollabNet.
+ * 
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ====================================================================
+ * 
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of CollabNet.
+ */
+
+
+import org.apache.turbine.Turbine;
+
+public class Environment 
+{
+
+    /**
+     * This class builds the API between the Scarab core and the configuration environment.
+     * Note: This is a Process in Work!
+     * <br/>
+     * 
+     * @authors hdab
+     */
+    
+    public static String getConfigurationProperty(String prop, String def)
+    {
+        String result = Turbine.getConfiguration().getString(prop);
+        if(result == null)
+        {
+            result = def;
+        }
+        return result;
+    }
+
+}

Modified: trunk/src/java/org/tigris/scarab/tools/ScarabGlobalTool.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/tools/ScarabGlobalTool.java?view=diff&pathrev=10991&r1=10990&r2=10991
==============================================================================
--- trunk/src/java/org/tigris/scarab/tools/ScarabGlobalTool.java	(original)
+++ trunk/src/java/org/tigris/scarab/tools/ScarabGlobalTool.java	2010-04-16 13:01:52-0700
@@ -156,7 +156,7 @@
     private FieldMethodizer parameterName = null;
 
     private static final String BUILD_VERSION = 
-        Turbine.getConfiguration().getString("scarab.build.version", "");
+        Environment.getConfigurationProperty("scarab.build.version", "");
 
     private static RenderContext context = new BaseRenderContext();
     private static RenderEngine engine = new ScarabRenderEngine();
@@ -831,7 +831,7 @@
     public String getSiteName()
     {
         String siteName = 
-            Turbine.getConfiguration().getString("scarab.site.name","");
+            Environment.getConfigurationProperty("scarab.site.name","");
 
         if (siteName == null)
         {
@@ -848,7 +848,7 @@
     public String getSiteLogo()
     {
         String siteLogo = 
-            Turbine.getConfiguration().getString("scarab.site.logo","");
+            Environment.getConfigurationProperty("scarab.site.logo","");
 
         if (siteLogo == null)
         {
@@ -868,7 +868,7 @@
     public int getPublicModulesDisplayCount()
     {
         String publicModulesDisplayCount = 
-            Turbine.getConfiguration().getString("scarab.public.modules.display.count","-1");
+            Environment.getConfigurationProperty("scarab.public.modules.display.count","-1");
         return Integer.parseInt(publicModulesDisplayCount);
     }
 
@@ -941,8 +941,7 @@
         {
             try
             {
-                moduleCodeLength = Integer.parseInt(Turbine.getConfiguration().
-                                   getString("scarab.module.code.length", "4"));
+                moduleCodeLength = Integer.parseInt(Environment.getConfigurationProperty("scarab.module.code.length", "4"));
             }
             catch (Exception e)
             {

Modified: trunk/src/java/org/tigris/scarab/tools/ScarabRequestTool.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/tools/ScarabRequestTool.java?view=diff&pathrev=10991&r1=10990&r2=10991
==============================================================================
--- trunk/src/java/org/tigris/scarab/tools/ScarabRequestTool.java	(original)
+++ trunk/src/java/org/tigris/scarab/tools/ScarabRequestTool.java	2010-04-16 13:01:52-0700
@@ -150,7 +150,7 @@
     implements ApplicationTool,Recyclable
 {
     private static final String TIME_ZONE =
-        Turbine.getConfiguration().getString("scarab.timezone", "");
+        Environment.getConfigurationProperty("scarab.timezone", "");
 
     private static final String POS_IN_LIST = "posInList";
 

Modified: trunk/src/java/org/tigris/scarab/workflow/IssueState.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/workflow/IssueState.java?view=diff&pathrev=10991&r1=10990&r2=10991
==============================================================================
--- trunk/src/java/org/tigris/scarab/workflow/IssueState.java	(original)
+++ trunk/src/java/org/tigris/scarab/workflow/IssueState.java	2010-04-16 13:01:52-0700
@@ -6,7 +6,6 @@
 import java.util.List;
 
 import org.apache.torque.TorqueException;
-import org.apache.turbine.Turbine;
 import org.tigris.scarab.attribute.DateAttribute;
 import org.tigris.scarab.om.Attribute;
 import org.tigris.scarab.om.AttributeValue;
@@ -15,6 +14,7 @@
 import org.tigris.scarab.om.IssueType;
 import org.tigris.scarab.om.Module;
 import org.tigris.scarab.om.RModuleAttribute;
+import org.tigris.scarab.tools.Environment;
 import org.tigris.scarab.util.ScarabException;
 import org.tigris.scarab.util.SimpleSkipFiltering;
 import org.tigris.scarab.util.SkipFiltering;
@@ -183,10 +183,10 @@
     public boolean isSealed() throws TorqueException
     {        
         boolean result = false;
-        String status = getProperty("scarab.common.status.id", null);
+        String status = Environment.getConfigurationProperty("scarab.common.status.id", null);
         if (status != null)
         {
-            String value = getProperty("scarab.common.status.sealed", null);
+            String value = Environment.getConfigurationProperty("scarab.common.status.sealed", null);
             if(value != null)
             {
                 AttributeValue attval = issue.getAttributeValue(status);
@@ -212,10 +212,10 @@
     public boolean isOnHold() throws TorqueException
     {        
         boolean result = false;
-        String status = getProperty("scarab.common.status.id", null);
+        String status = Environment.getConfigurationProperty("scarab.common.status.id", null);
         if (status != null)
         {
-            String value = getProperty("scarab.common.status.onhold", null);
+            String value = Environment.getConfigurationProperty("scarab.common.status.onhold", null);
             if(value != null)
             {
                 AttributeValue attval = issue.getAttributeValue(status);
@@ -249,7 +249,7 @@
     public Attribute getStatusAttribute() throws TorqueException
     {
         Attribute attribute = null;
-        String attributeName = getProperty("scarab.common.status.id", null);
+        String attributeName = Environment.getConfigurationProperty("scarab.common.status.id", null);
         if(attributeName != null)
         {
             attribute = issue.getAttribute(attributeName);
@@ -266,7 +266,7 @@
     public Attribute getOnHoldExpirationDate() throws TorqueException
     {
         Attribute attribute = null;
-        String attributeName = getProperty("scarab.common.status.onhold.dateProperty", null);
+        String attributeName = Environment.getConfigurationProperty("scarab.common.status.onhold.dateProperty", null);
         if(attributeName != null)
         {
             attribute = issue.getAttribute(attributeName);
@@ -286,7 +286,7 @@
     public Date getOnHoldUntil() throws TorqueException, ParseException
     {
         Date date = null;
-        String attributeName = getProperty("scarab.common.status.onhold.dateProperty", null);
+        String attributeName = Environment.getConfigurationProperty("scarab.common.status.onhold.dateProperty", null);
         
         if (attributeName != null)
         {
@@ -312,7 +312,7 @@
      */
     public int getReminderPeriod()
     {
-        String rp = getProperty("scarab.common.status.onhold.reminder.period", null);
+        String rp = Environment.getConfigurationProperty("scarab.common.status.onhold.reminder.period", null);
         int result = 0;
         if (rp != null)
         {
@@ -320,22 +320,5 @@
         }
         return result;
     }
-    
-    
-    /**
-     * helper funtion to retrieve properties from the Turbine Configuration sysstem.
-     * @param prop
-     * @param def
-     * @return
-     */
-    private String getProperty(String prop, String def)
-    {
-        String result = (String)Turbine.getConfiguration().getProperty(prop);
-        if(result == null)
-        {
-            result = def;
-        }
-        return result;
-    }
-    
+        
 }

------------------------------------------------------
http://scarab.tigris.org/ds/viewMessage.do?dsForumId=3577&dsMessageId=2585695