package org.flymine.web.widget;

/*
 * Copyright (C) 2002-2009 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import org.intermine.objectstore.ObjectStore;
import org.intermine.pathquery.Constraints;
import org.intermine.pathquery.PathQuery;
import org.intermine.web.logic.bag.InterMineBag;
import org.intermine.web.logic.widget.WidgetURLQuery;

/**
 * Builds a query to get all the genes (in bag) associated with specified go term.
 * @author Julie Sullivan
 */
public class TiffinURLQuery implements WidgetURLQuery
{

    private InterMineBag bag;
    private String key;
    private ObjectStore os;
    private static final String DATASET = "Tiffin";
    
    /**
     * @param key which bar the user clicked on
     * @param bag bag
     * @param os object store
     */
    public TiffinURLQuery(ObjectStore os, InterMineBag bag, String key) {
        this.bag = bag;
        this.key = key;
        this.os = os;
    }

    /**
     * {@inheritDoc}
     */
    public PathQuery generatePathQuery() {        
        // can't do this properly until #2184 if fixed
        PathQuery q = new PathQuery(os.getModel());
//        String viewStrings = "Gene.secondaryIdentifier";
//        String tiffin  = "Gene.upstreamIntergenicRegion.overlappingFeatures[TFBindingSite].motif.primaryIdentifier";
        String tiffin = "TFBindingSite.motif.primaryIdentifier";
//        q.setView(viewStrings);
        q.addView(tiffin);
//        q.addConstraint(bag.getType(),  Constraints.in(bag.getName()));
        q.addConstraint(tiffin, Constraints.eq
                        (key));
        q.addConstraint("TFBindingSite.dataSets.title", Constraints.eq(DATASET));
        q.setConstraintLogic("A and B");
        q.syncLogicExpression("and");
        q.setOrderBy(tiffin);
        return q;
    }
}


@@ -1223,71 +1223,8 @@
 () %7B
-        %0A        // can't do this properly until #2184 if fixed
 %0A   
@@ -1272,18 +1272,16 @@
 del());%0A
-//
         
@@ -1321,34 +1321,32 @@
 aryIdentifier%22;%0A
-//
         String t
@@ -1438,32 +1438,34 @@
 aryIdentifier%22;%0A
+//
         String t
@@ -1505,34 +1505,32 @@
 aryIdentifier%22;%0A
-//
         q.setVie
@@ -1545,16 +1545,18 @@
 rings);%0A
+//
         
@@ -1574,18 +1574,16 @@
 iffin);%0A
-//
         
@@ -1696,32 +1696,8 @@
 s.eq
-%0A                       
  (ke
@@ -1820,16 +1820,22 @@
 %22A and B
+ and C
 %22);%0A    

check in broken widget so Matthew can see it.