package org.intermine.web.logic.widget.config;

/*
 * Copyright (C) 2002-2011 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 java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.intermine.api.profile.InterMineBag;
import org.intermine.objectstore.ObjectStore;
import org.intermine.web.logic.widget.GraphWidget;

/**
 * Configuration object describing details of a graph displayer
 *
 * @author Xavier Watkins
 */
public class GraphWidgetConfig extends WidgetConfig
{
    private static final Logger LOG = Logger.getLogger(GraphWidgetConfig.class);
    private String domainLabel;
    private String rangeLabel;
    private String graphType;
    private String bagType;
    private String bagPath;
    private String categoryPath;
    private String seriesPath;
    private String seriesValues;
    private String seriesLabels;
    private HttpSession session;
    private String editable;
    public static final String ACTUAL_EXPECTED_CRITERIA = "ActualExpectedCriteria";

    /**
     * Get the session
     * @return the session
     */
    public HttpSession getSession() {
        return session;
    }

    /**
     * @param session the session to set
     */
    public void setSession(HttpSession session) {
        this.session = session;
    }

    /**
     * Get the domainLabel
     * @return the domainLabel
     */
    public String getDomainLabel() {
        return domainLabel;
    }


    /**
     * Set the value of domainLabel
     * @param domainLabel a String
     */
    public void setDomainLabel(String domainLabel) {
        this.domainLabel = domainLabel;
    }


    /**
     * Get the value of rangeLabel
     * @return the rangeLabel
     */
    public String getRangeLabel() {
        return rangeLabel;
    }


    /**
     * Set the value of rangeLabel
     * @param rangeLabel a String
     */
    public void setRangeLabel(String rangeLabel) {
        this.rangeLabel = rangeLabel;
    }

    /**
     * @param graphType type of graph, e.g. BarChart, StackedBarChart
     */
    public void setGraphType(String graphType) {
        this.graphType = graphType;
    }


    /**
     * Get the type of this graph, e.g. BarChart, StackedBarChart
     * @return the type of this graph
     */
    public String getGraphType() {
        return graphType;
    }

    /**
     * Return an XML String of this Type object
     * @return a String version of this WebConfig object
     */
    public String toString() {
        return "< title=\"" + getTitle() + " domainLabel=\"" + domainLabel + " rangeLabel=\""
               + rangeLabel + " />";
    }

    public String getBagType() {
        return bagType;
    }

    public void setBagType(String bagType) {
        this.bagType = bagType;
    }

    public String getBagPath() {
        return bagPath;
    }

    public void setBagPath(String bagPath) {
        this.bagPath = bagPath;
    }

    public boolean isBagPathSet() {
        if (bagPath != null && !"".equals(bagPath)) {
            return true;
        }
        return false;
    }

    public String getCategoryPath() {
        return categoryPath;
    }

    public void setCategoryPath(String categoryPath) {
        this.categoryPath = categoryPath;
    }

    public String getSeriesPath() {
        return seriesPath;
    }

    public void setSeriesPath(String seriesPath) {
        this.seriesPath = seriesPath;
    }

    public boolean isActualExpectedCriteria() {
        if (this.seriesPath.contains(ACTUAL_EXPECTED_CRITERIA)) {
            return true;
        }
        return false;
    }

    public String getSeriesValues() {
        return seriesValues;
    }

    public void setSeriesValues(String seriesValues) {
        this.seriesValues = seriesValues;
    }

    public String getSeriesLabels() {
        return seriesLabels;
    }

    public void setSeriesLabels(String seriesLabels) {
        this.seriesLabels = seriesLabels;
    }

    /**
     * @return the editable attribute
     */
    public String geteditable() {
        return editable;
    }

    /**
     * @param editable editable
     */
    public void seteditable(String editable) {
        this.editable = editable;
    }

    /**
     * {@inheritDoc}
     */
    public Map<String, Collection<String>> getExtraAttributes(InterMineBag imBag, ObjectStore os)
        throws Exception {
        Collection<String> extraAttributes = new ArrayList<String>();
        Map<String, Collection<String>> returnMap = new HashMap<String, Collection<String>>();
/*        if (extraAttributeClass != null && extraAttributeClass.length() > 0) {
            try {
                Class<?> clazz = TypeUtil.instantiate(extraAttributeClass);
                Method extraAttributeMethod = clazz.getMethod("getExtraAttributes",
                            new Class[] {ObjectStore.class, InterMineBag.class});
                // invoking a static method the first argument is ignored
                extraAttributes = (Collection<String>) extraAttributeMethod.invoke(null, os, imBag);
            } catch (Exception e) {
                LOG.error(e.getMessage());
                return returnMap;
            }
        }
        if (extraAttributes.size() > 0) {
            returnMap.put("Organism", extraAttributes);
        }
        if (editable != null && "true".equals(editable)) {
            returnMap.put("Editable", new ArrayList<String>());
        }*/
        return returnMap;
    }

    /**
     * {@inheritDoc}
     */
    public GraphWidget getWidget(InterMineBag imBag, ObjectStore os,
                                 List<String> selectedExtraAttribute) {
        return new GraphWidget(this, imBag, os, selectedExtraAttribute.get(0));
    }

}

@@ -4868,904 +4868,8 @@
 ();%0A
-/*        if (extraAttributeClass != null && extraAttributeClass.length() %3E 0) %7B%0A            try %7B%0A                Class%3C?%3E clazz = TypeUtil.instantiate(extraAttributeClass);%0A                Method extraAttributeMethod = clazz.getMethod(%22getExtraAttributes%22,%0A                            new Class%5B%5D %7BObjectStore.class, InterMineBag.class%7D);%0A                // invoking a static method the first argument is ignored%0A                extraAttributes = (Collection%3CString%3E) extraAttributeMethod.invoke(null, os, imBag);%0A            %7D catch (Exception e) %7B%0A                LOG.error(e.getMessage());%0A                return returnMap;%0A            %7D%0A        %7D%0A        if (extraAttributes.size() %3E 0) %7B%0A            returnMap.put(%22Organism%22, extraAttributes);%0A        %7D%0A        if (editable != null && %22true%22.equals(editable)) %7B%0A            returnMap.put(%22Editable%22, new ArrayList%3CString%3E());%0A        %7D*/%0A
     

clean code commented out