/*
 *  @author: SahniH
 *  Created on Oct 31, 2004
 *  @version $ Revision: 1.0 $
 * 
 *	The caBIO Software License, Version 1.0
 *
 *	Copyright 2004 SAIC. This software was developed in conjunction with the National Cancer 
 *	Institute, and so to the extent government employees are co-authors, any rights in such works 
 *	shall be subject to Title 17 of the United States Code, section 105.
 * 
 *	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 disclaimer of Article 3, below.  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.
 * 
 *	2.  The end-user documentation included with the redistribution, if any, must include the 
 *	following acknowledgment:
 *	
 *	"This product includes software developed by the SAIC and the National Cancer 
 *	Institute."
 *	
 *	If no such end-user documentation is to be included, this acknowledgment shall appear in the 
 *	software itself, wherever such third-party acknowledgments normally appear.
 *	 
 *	3. The names "The National Cancer Institute", "NCI" and "SAIC" must not be used to endorse or 
 *	promote products derived from this software.
 *	 
 *	4. This license does not authorize the incorporation of this software into any proprietary 
 *	programs.  This license does not authorize the recipient to use any trademarks owned by either 
 *	NCI or SAIC-Frederick.
 *	 
 *	
 *	5. 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 THE NATIONAL CANCER INSTITUTE, SAIC, OR 
 *	THEIR AFFILIATES 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.
 *	
 */
package gov.nih.nci.nautilus.resultset;
import gov.nih.nci.nautilus.query.QueryManager;
import gov.nih.nci.nautilus.query.Queriable;
import gov.nih.nci.nautilus.queryprocessing.cgh.CopyNumber;
import gov.nih.nci.nautilus.queryprocessing.ge.GeneExpr.GeneExprGroup;
import gov.nih.nci.nautilus.queryprocessing.ge.GeneExpr.GeneExprSingle;
import gov.nih.nci.nautilus.view.CopyNumberSampleView;
import gov.nih.nci.nautilus.view.GeneExprDiseaseView;
import gov.nih.nci.nautilus.view.GeneExprSampleView;
import gov.nih.nci.nautilus.view.GroupType;
import gov.nih.nci.nautilus.view.ViewType;
import gov.nih.nci.nautilus.view.Viewable;



public class ResultsetManager {
    public static Resultant executeQuery(Queriable queryToExecute) throws Exception {
    	Resultant resultant= new Resultant();
    	if(queryToExecute != null ){
        Viewable associatedView = queryToExecute.getAssociatedView();
        ResultSet[] resultsets = QueryManager.executeQuery(queryToExecute);
    	if (resultsets instanceof GeneExprSingle[]){
    		    GeneExprSampleView geneExprSampleView = (GeneExprSampleView) associatedView;
    			GroupType groupType = geneExprSampleView.getGroupType();
    			ResultsContainer resultsContainer = ResultsetProcessor.handleGeneExprSingleView((GeneExprSingle[]) resultsets,groupType);
    			resultant.setResultsContainer(resultsContainer);
    			resultant.setAssociatedQuery(queryToExecute);
    			resultant.setAssociatedView(associatedView);
    		}
    	else if (resultsets instanceof GeneExprGroup[]){
    		GeneExprDiseaseView geneExprDiseaseView = (GeneExprDiseaseView) associatedView;
			ResultsContainer resultsContainer = ResultsetProcessor.handleGeneExprDiseaseView((GeneExprGroup[]) resultsets);
			resultant.setResultsContainer(resultsContainer);
			resultant.setAssociatedQuery(queryToExecute);
			resultant.setAssociatedView(associatedView);
		}
    	else if (resultsets instanceof CopyNumber[]){
    		CopyNumberSampleView copyNumberView = (CopyNumberSampleView) associatedView;
    		GroupType groupType = copyNumberView.getGroupType();
			ResultsContainer resultsContainer = ResultsetProcessor.handleCopyNumberSingleView((CopyNumber[]) resultsets, groupType);
			resultant.setResultsContainer(resultsContainer);
			resultant.setAssociatedQuery(queryToExecute);
			resultant.setAssociatedView(associatedView);
		}
    	
    	
    	
    	
    	}
        return resultant;
    }

}

@@ -3523,60 +3523,174 @@
   %09%09
-    GeneExprSampleView geneExprSampleView = (GeneExp
+GroupType groupType = GroupType.DISEASE_TYPE_GROUP;%0A    %09%09if (associatedView instanceof CopyNumberSampleView)%7B%0A    %09%09%09CopyNumberSampleView copyNumberView = (CopyNumbe
 rSam
@@ -3721,26 +3721,16 @@
 %0A    %09%09%09
-GroupType 
 groupTyp
@@ -3737,22 +3737,18 @@
 e = 
-geneExprSample
+copyNumber
 View
@@ -3760,24 +3760,32 @@
 roupType();%0A
+    %09%09%7D%0A
     %09%09%09Resul
@@ -4535,16 +4535,134 @@
 %7B%0A    %09%09
+GroupType groupType = GroupType.DISEASE_TYPE_GROUP;%0A    %09%09if (associatedView instanceof CopyNumberSampleView)%7B%0A    %09%09%09
 CopyNumb
@@ -4732,34 +4732,25 @@
 View;%0A    %09%09
-GroupType 
+%09
 groupType = 
@@ -4780,16 +4780,24 @@
 Type();%0A
+    %09%09%7D%0A
 %09%09%09Resul

handle group type