Scarab commit: svn commit: r10778 - trunk/src/java/org/tigris/scarab/tools/ScarabRequestTool.java

Hussayn Dabbous <[email protected]>
Newsgroups gmane.comp.java.scarab.cvs
Message-ID <[email protected]>
Author: dabbous
Date: 2009-07-10 14:16:35-0700
New Revision: 10778

Modified:
   trunk/src/java/org/tigris/scarab/tools/ScarabRequestTool.java

Log:
SCB2675: Added support for "default customization"
Now scarab copies the configuration (the list of RModuleAttributes) 
of the owner of a query to the current user's set of RModuleAttributes.


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=10778&r1=10777&r2=10778
==============================================================================
--- trunk/src/java/org/tigris/scarab/tools/ScarabRequestTool.java	(original)
+++ trunk/src/java/org/tigris/scarab/tools/ScarabRequestTool.java	2009-07-10 14:16:35-0700
@@ -598,15 +598,21 @@
      * empty, then it will try to get the defaults from the module. If anything
      * fails, it will return an empty list.
      */
-    private List getRModuleUserAttributes(ScarabUser user, Module module, IssueType issueType) {
-        List issueListColumns = null;
+    private List<RModuleAttribute> getRModuleUserAttributes(ScarabUser user, Module module, IssueType issueType) 
+    {
+        MITList currentList = user.getCurrentMITList();
+        return getRModuleUserAttributes(user, module, issueType, currentList);
+    }
+    
+    private List<RModuleAttribute> getRModuleUserAttributes(ScarabUser user, Module module, IssueType issueType, MITList currentList) 
+    {
+        List<RModuleAttribute> issueListColumns = null;
         try {
             //
             // First check whether an MIT list is currently
             // active and if so, whether it has attributes
             // associated with it.
             //
-            MITList currentList = user.getCurrentMITList();
             if (currentList != null) {
                 //
                 // Here we fetch the collection of attributes
@@ -634,14 +640,15 @@
                 // TODO looking for common default attributes.
             }
 
-            if (issueListColumns == null) {
-                issueListColumns = user.getRModuleUserAttributes(module,
-                        issueType);
-                if (issueListColumns.isEmpty()) {
-                    issueListColumns = module
-                            .getDefaultRModuleUserAttributes(issueType);
+            if (issueListColumns == null || issueListColumns.size() == 0)
+            {
+                issueListColumns = user.getRModuleUserAttributes(module, issueType);
+                if (issueListColumns.isEmpty()) 
+                {
+                    issueListColumns = module.getDefaultRModuleUserAttributes(issueType);
                 }
             }
+            
             if (issueListColumns == null)
             {
                 issueListColumns = Collections.EMPTY_LIST;
@@ -697,13 +704,68 @@
      * If it is empty, then it will try to get the defaults from the module.
      * If anything fails, it will return an empty list.
      */
-    public List getRModuleUserAttributes()
+    public List<RModuleAttribute> getRModuleUserAttributes()
+    {
+        ScarabUser user = (ScarabUser)data.getUser();
+        Module module   = user.getCurrentModule();
+        List<RModuleAttribute> result = getRModuleUserAttributes(user, module);
+        return result;
+    }
+
+    /**
+     * Same as above, but also allows to get the Attributes set from the 
+     * query owners definition, if the current user has not defined his/her
+     * own query attribute set for this query.
+     * @param q
+     * @return
+     * @throws TorqueException
+     */
+    public List<RModuleAttribute> getRModuleUserAttributes(Query q) throws TorqueException
+    {
+        List<RModuleAttribute> result = getRModuleUserAttributes();
+        if(result.size() == 0) 
+        {
+            /*
+             * When we get here, then the current user uses a public query for which
+             * he/she has not yet created a customization (ake call s the query for the
+             * first time ever). Since we assume, that the original creator of the 
+             * query has configured the query wisely, we take a copy of the creators 
+             * customization here. Hence the new user gets a reasonable default setting.
+             * However the new user can configure the query independently from the originators
+             * customization.
+             */
+            ScarabUser me       = (ScarabUser)data.getUser();  // the userId of the current user
+            MITList currentList = q.getMITList();              // The query MIT-list
+            ScarabUser owner    = q.getScarabUser();           // The originator of the query
+            Module module       = me.getCurrentModule();       // The current module
+            IssueType theIssueType = this.getIssueType();      // The current issue Type
+            currentList = currentList.copy();                  // Here we make a physical copy
+            currentList.setUserId(owner.getUserId());          // We set the current users uid 
+
+            /*
+             * Now we recall the Userattributes of the originators customisation,
+             * but get it in to our copy. The nice side effect: The copy will be
+             * added to the database, thus it gets persistent. Subsequent calls
+             * to this method will always return the copy from the database.
+            */
+            result = getRModuleUserAttributes(owner, module, theIssueType, currentList );
+            
+        }
+        return result;
+    }
+    
+    /**
+     * Common driver function to get the current list of RModule Attributes.
+     * @param user
+     * @return
+     */
+    private List<RModuleAttribute> getRModuleUserAttributes(ScarabUser user, Module module)
     {
-        ScarabUser user = (ScarabUser)data.getUser();        
         IssueType theIssueType = this.getIssueType();
 
-        if(issueListColumns == null){
-        	issueListColumns= getRModuleUserAttributes(user, user.getCurrentModule(), theIssueType);
+        if(issueListColumns == null || issueListColumns.size() == 0)
+        {
+        	issueListColumns= getRModuleUserAttributes(user, module, theIssueType);
 			if (issueListColumns == null)
 	        {
 	            issueListColumns = Collections.EMPTY_LIST;
@@ -722,6 +784,7 @@
     }
 
 
+
     public List getValidIssueListAttributes()
     {
         List result = getIssueListAttributes(false,true);
@@ -1700,9 +1763,10 @@
         throws Exception
     {
         IssueSearch search = getNewSearch();
+        Query theQuery = this.getQuery();
 
         search.setLocale(getLocalizationTool().getPrimaryLocale());
-        search.setIssueListAttributeColumns(getRModuleUserAttributes());
+        search.setIssueListAttributeColumns(getRModuleUserAttributes(theQuery));
         search.setLocalizationTool(getLocalizationTool());
 
         StringValueParser parser = ScarabUtil.parseURL(query);

------------------------------------------------------
http://scarab.tigris.org/ds/viewMessage.do?dsForumId=3577&dsMessageId=2370339
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.