view gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java @ 420:c6a287398379

Outsourcing of some methods for preparing results for chart creation. gnv-artifacts/trunk@468 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 21 Dec 2009 15:57:04 +0000
parents 6eae1efb5fc3
children 2402173a1490
line wrap: on
line source
/**
 *
 */
package de.intevation.gnv.state.profile.horizontal;

import java.util.Collection;
import java.util.Locale;

import org.apache.log4j.Logger;
import org.w3c.dom.Node;

import com.vividsolutions.jts.io.ParseException;

import de.intevation.artifactdatabase.Config;

import de.intevation.gnv.artifacts.cache.CacheFactory;

import de.intevation.gnv.chart.Chart;
import de.intevation.gnv.chart.ChartLabels;
import de.intevation.gnv.chart.HorizontalCrossProfileChart;

import de.intevation.gnv.geobackend.base.Result;

import de.intevation.gnv.geobackend.base.query.exception.QueryException;

import de.intevation.gnv.utils.WKTUtils;

import org.jfree.chart.ChartTheme;

/**
 * @author Tim Englich <tim.englich@intevation.de>
 *
 */
public class HorizontalProfileMeshCrossOutputState extends
                                                  HorizontalProfileOutputState {

    /**
     *
     */
    private static final long serialVersionUID = 2205958041745637263L;
    
    /**
     * the logger, used to log exceptions and additonaly information
     */
    private static Logger log = 
                  Logger.getLogger(HorizontalProfileMeshCrossOutputState.class);
    

    private String ijkQueryID = null;
   
    /**
     * Constructor
     */
    public HorizontalProfileMeshCrossOutputState() {
        super();
    }
    
    /**
     * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#setup(org.w3c.dom.Node)
     */
    @Override
    public void setup(Node configuration) {
        super.setup(configuration);
        this.ijkQueryID = Config.getStringXPath(configuration,"queryID-ijk");
        
    }


    @Override
    protected Chart getChart(
        ChartLabels  chartLables,
        ChartTheme   theme,
        Collection   parameters,
        Collection   measurements,
        Collection   dates,
        Collection   result,
        Locale       locale,
        String       uuid,
        boolean      linesVisible,
        boolean      shapesVisible
    ) {
        Chart chart = null;
        if (CACHE_CHART) {
            log.info("Try to get horizontalprofilemeshcross chart from cache.");
            chart = (Chart) getChartFromCache(uuid);
        }

        if (chart != null)
            return chart;

        log.info("Chart not in cache yet.");
        chart = new HorizontalCrossProfileChart(
            chartLables,
            theme,
            parameters,
            measurements,
            dates,
            result,
            null,
            locale,
            linesVisible,
            shapesVisible
        );
        chart.generateChart();

        if (CACHE_CHART) {
            log.info("Put chart into cache.");
            purifyChart(chart, uuid);
        }

        return chart;
    }

    @Override
    protected Collection<Result> getChartResult(String uuid) {
        log.debug("HorizontalProfileMeshCrossOutputState.getChartResult");
        Collection<Result> result = null;
        if (CacheFactory.getInstance().isInitialized()) {
            String key = uuid + super.getID();
            log.debug("Hash for Queryelements: " + key);
            net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key);
            if (value != null) {
                result = (Collection<Result>) (value.getObjectValue());
            }else{
                
                if (this.inputData.containsKey("mesh_linestring")){
                    
                    try {
                        result = WKTUtils.worldCoordinatesToIndex(
                            result,
                            inputData,
                            ijkQueryID,
                            queryID,
                            generateFilterValuesFromInputData()
                        );
                    } catch (ParseException e) {
                        log.error(e,e);
                    }catch (QueryException e) {
                        log.error(e,e);
                    }
                }else{
                    // TODO: definieren was passiert wenn kein linestring vorhanden ist.
                }
                
                if (CacheFactory.getInstance().isInitialized()) {
                    CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, result));
                }
                
            }
        }
        return result;
    }


    @Override
    protected String createChartSubtitle(Locale locale, String uuid) {
        log.debug("create chart subtitle for horizontal crossprofile charts.");
        String subtitle = createTimePeriod(locale, uuid);

        return subtitle;
    }
}

http://dive4elements.wald.intevation.org