From a112357c6c24cc6c23eb108f33df57b1ccb0af8c Mon Sep 17 00:00:00 2001
From: Mike McKay <mfmckay@wustl.edu>
Date: Sat, 23 Apr 2016 10:56:27 -0500
Subject: [PATCH] XNAT-3964 Fixed Advanced Search.

---
 .../screens/XDATScreen_search_wizard2.java    | 28 +++++++++++++++----
 .../screens/XDATScreen_search_wizard2.vm      | 16 +++++------
 2 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/nrg/xnat/turbine/modules/screens/XDATScreen_search_wizard2.java b/src/main/java/org/nrg/xnat/turbine/modules/screens/XDATScreen_search_wizard2.java
index 6104fc3f..a390ac8b 100644
--- a/src/main/java/org/nrg/xnat/turbine/modules/screens/XDATScreen_search_wizard2.java
+++ b/src/main/java/org/nrg/xnat/turbine/modules/screens/XDATScreen_search_wizard2.java
@@ -10,27 +10,45 @@
  */
 package org.nrg.xnat.turbine.modules.screens;
 
-import java.util.Hashtable;
-import java.util.Map;
-
 import org.apache.turbine.util.RunData;
 import org.apache.velocity.context.Context;
 import org.nrg.xdat.display.ElementDisplay;
+import org.nrg.xdat.schema.SchemaElement;
 import org.nrg.xdat.security.helpers.UserHelper;
 import org.nrg.xdat.turbine.modules.screens.SecureScreen;
 import org.nrg.xdat.turbine.utils.TurbineUtils;
+import org.nrg.xft.security.UserI;
+
+import java.util.Hashtable;
+import java.util.Map;
 
 public class XDATScreen_search_wizard2 extends SecureScreen {
 
 	@Override
 	protected void doBuildTemplate(RunData data, Context context) throws Exception {
+		UserI user = TurbineUtils.getUser(data);
 		Map<String,Object> additional=new Hashtable<String,Object>();
+		Map<String,Object> additionalDescriptions=new Hashtable<String,Object>();
+		Map<String,Object> additionalSchemaElements=new Hashtable<String,Object>();
+		Object elementZero = TurbineUtils.GetPassedParameter("ELEMENT_0", data);
 		context.put("ELEMENT_0", TurbineUtils.GetPassedParameter("ELEMENT_0", data));
 		for(ElementDisplay ed : UserHelper.getUserHelperService(TurbineUtils.getUser(data)).getSearchableElementDisplaysByPluralDesc()){
-			if(TurbineUtils.HasPassedParameter("super_"+ed.getElementName(), data))
-				additional.put(ed.getElementName(), TurbineUtils.GetPassedParameter("super_"+ed.getElementName(), data));
+			if(TurbineUtils.HasPassedParameter("super_"+ed.getElementName(), data)) {
+				Object superElement = TurbineUtils.GetPassedParameter("super_" + ed.getElementName(), data);
+				additional.put(ed.getElementName(), superElement);
+				additionalDescriptions.put(ed.getElementName(), UserHelper.getUserHelperService(user).getElementSecurity(ed.getElementName()).getPluralDescription());
+				additionalSchemaElements.put(ed.getElementName(), UserHelper.getUserHelperService(user).getElementSecurity(ed.getElementName()).getSchemaElement());
+			}
 		}
 		
 		context.put("additional_types", additional);
+		context.put("additional_descriptions", additionalDescriptions);
+		context.put("additional_schema_elements", additionalSchemaElements);
+
+		String pivotDescription = UserHelper.getUserHelperService(user).getElementSecurity(elementZero.toString()).getPluralDescription();
+		context.put("pivot_description", pivotDescription);
+		SchemaElement pivotSchemaElement = UserHelper.getUserHelperService(user).getElementSecurity(elementZero.toString()).getSchemaElement();
+		context.put("pivot_schema_element", pivotSchemaElement);
+
 	}
 }
diff --git a/src/main/webapp/xnat-templates/screens/XDATScreen_search_wizard2.vm b/src/main/webapp/xnat-templates/screens/XDATScreen_search_wizard2.vm
index 1ae137f8..8a41e47b 100644
--- a/src/main/webapp/xnat-templates/screens/XDATScreen_search_wizard2.vm
+++ b/src/main/webapp/xnat-templates/screens/XDATScreen_search_wizard2.vm
@@ -24,7 +24,7 @@
     <ol class="steps">
 
         <li class="step1">
-            <h3>Pivot Data-type: $user.getElementSecurity($ELEMENT_0).getPluralDescription()</h3>
+            <h3>Pivot Data-type: $pivot_description</h3>
             <input type="hidden" name="ELEMENT_0" value="$ELEMENT_0">
         </li>
 
@@ -36,7 +36,7 @@
                     #foreach ($key in $additional_types.keySet())
                         <tr>
                             <td>
-                                <b>$user.getElementSecurity($key).getPluralDescription()</b>
+                                <b>$additional_descriptions.get($key)</b>
                             </td>
                             <td nowrap>
                                 $additional_types.get($key)
@@ -68,24 +68,24 @@
             <div id="super_search" class="yui-navset" style="max-width:800px !important;margin-top:30px;margin-left:-40px;">
                 <ul class="yui-nav" style="">
                     <li class="selected">
-                        <a href="#$ELEMENT_0"><em>$user.getElementSecurity($ELEMENT_0).getPluralDescription()</em></a>
+                        <a href="#$ELEMENT_0"><em>$pivot_description</em></a>
                     </li>
-                    #foreach ($key in $additional_types.keySet())
+                    #foreach ($key in $additional_descriptions.keySet())
                         #if(!$key.equals($ELEMENT_0))
                             <li>
-                                <a href="#$key"><em>$user.getElementSecurity($key).getPluralDescription()</em></a>
+                                <a href="#$key"><em>$additional_descriptions.get($key)</em></a>
                             </li>
                         #end
                     #end
                 </ul>
                 <div class="yui-content">
                     <div id="$ELEMENT_0">
-                        <p>#xdatSearchElement($user.getElementSecurity($ELEMENT_0).getSchemaElement() 3)</p>
+                        <p>#xdatSearchElement($pivot_schema_element 3)</p>
                     </div>
-                    #foreach ($key in $additional_types.keySet())
+                    #foreach ($key in $additional_schema_elements.keySet())
                         #if(!$key.equals($ELEMENT_0))
                             <div id="$key">
-                                <p>#xdatSearchElement($user.getElementSecurity($key).getSchemaElement() 3)</p>
+                                <p>#xdatSearchElement($additional_schema_elements.get($key) 3)</p>
                             </div>
                         #end
                     #end
-- 
GitLab