⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 querybuildertask.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
package com.esri.solutions.jitk.web.tasks.query.querybuilder;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.faces.context.FacesContext;
import org.apache.log4j.Logger;

import com.esri.adf.web.ags.data.AGSLocalMapResource;
import com.esri.adf.web.ags.data.AGSMapResource;
import com.esri.adf.web.aims.data.AIMSMapResource;
import com.esri.adf.web.data.GISResource;
import com.esri.adf.web.data.GraphicElement;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebGraphics;
import com.esri.adf.web.data.WebLayerInfo;
import com.esri.adf.web.data.WebMap;
import com.esri.adf.web.data.geometry.WebCircle;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.data.geometry.WebGeometry;
import com.esri.adf.web.data.geometry.WebOval;
import com.esri.adf.web.data.geometry.WebPoint;
import com.esri.adf.web.data.geometry.WebPolygon;
import com.esri.adf.web.data.geometry.WebPolyline;
import com.esri.adf.web.data.query.QueryResult;
import com.esri.adf.web.data.query.WebQuery;
import com.esri.adf.web.data.symbol.WebSimpleMarkerSymbol;
import com.esri.adf.web.data.symbol.WebSimplePolygonSymbol;
import com.esri.adf.web.data.symbol.WebSymbol;
import com.esri.adf.web.data.tasks.TaskActionDescriptor;
import com.esri.adf.web.data.tasks.TaskInfo;
import com.esri.adf.web.faces.event.MapEvent;
import com.esri.adf.web.faces.event.TaskEvent;
import com.esri.solutions.jitk.common.geometry.GeometryConverter;
import com.esri.solutions.jitk.common.personalization.IPersonalizable;
import com.esri.solutions.jitk.common.personalization.IPersonalizationContext;
import com.esri.solutions.jitk.common.personalization.PersonalizationGeometryConverter;
import com.esri.solutions.jitk.common.querybuilder.QbPersistenceObject;
import com.esri.solutions.jitk.common.querybuilder.QbPersistenceService;
import com.esri.solutions.jitk.common.resources.TextResources;
import com.esri.solutions.jitk.common.web.layer.WebLayerInfoUtil;
import com.esri.solutions.jitk.personalization.PersonalizationException;
import com.esri.solutions.jitk.personalization.data.IQuery;
import com.esri.solutions.jitk.personalization.data.beans.v1.AgsInternetServiceType;
import com.esri.solutions.jitk.personalization.data.beans.v1.AgsLocalServiceType;
import com.esri.solutions.jitk.personalization.data.beans.v1.ArcImsInternetServiceType;
import com.esri.solutions.jitk.personalization.data.beans.v1.ArcImsTcpServiceType;
import com.esri.solutions.jitk.personalization.data.beans.v1.HostList;
import com.esri.solutions.jitk.personalization.data.beans.v1.MapServiceList;
import com.esri.solutions.jitk.personalization.data.beans.v1.MapServiceType;
import com.esri.solutions.jitk.personalization.data.beans.v1.ObjectFactory;
import com.esri.solutions.jitk.personalization.data.beans.v1.PointN;
import com.esri.solutions.jitk.personalization.data.beans.v1.PolygonN;
import com.esri.solutions.jitk.personalization.data.beans.v1.WfsServiceType;
import com.esri.solutions.jitk.personalization.data.beans.v1.MapServiceList.MapServiceItemType;
import com.esri.solutions.jitk.web.tasks.ResultProducingTask;
import com.esri.solutions.jitk.web.tasks.mapcomp.IADFToBeanConverter;
import com.esri.solutions.jitk.web.tasks.mapcomp.IBeanToADFConverter;
import com.esri.solutions.jitk.web.tasks.mapcomp.IMapCompositionEventObserver;
import com.esri.solutions.jitk.web.tasks.mapcomp.MapCompositionEvent;
import com.esri.solutions.jitk.web.tasks.redlining.map.PointMarkerMap;
import com.esri.solutions.jitk.web.tasks.resources.ResourceAdder;
import com.esri.solutions.jitk.web.wfs.data.WFSMapResource;


/**
 * This task allows users to define queries using both spatial and non-spatial terms,
 * without requiring end user knowledge of SQL.
 */
@SuppressWarnings({"unchecked",
    "deprecation"
})
public class QueryBuilderTask extends ResultProducingTask
    implements IPersonalizable, IMapCompositionEventObserver {
    private static final long serialVersionUID = -60041702331996998L;
    private static final Logger _logger = Logger.getLogger(QueryBuilderTask.class.getName());
    private static final Integer SAVE_QUERY_REPOSITORY = 1;
    private static final Integer SAVE_QUERY_LOCAL = 2;
    private static final Integer LOAD_QUERY_REPOSITORY = 1;
    private static final Integer LOAD_QUERY_LOCAL = 2;
    private QueryBuilderTaskInfo taskInfo = null;
    private String taskName = null;
    private LinkedHashMap<String, String> layerList = null;
    private LinkedHashMap<String, String> spatialLayerList = null;
    private LinkedHashMap<String, String> attributeList = null;
    private LinkedHashMap<String, String> operationList = null;
    private LinkedHashMap<String, String> spatialOperationList = null;
    private LinkedHashMap<String, String> domainValueList = null;
    private String attributeSelection = "domainValue";
    private String spatialFilterSelection = "graphics";
    private String layer = null;
    private String layerName = null;
    private String spatialLayer = "";
    private String attribute = "";
    private String operation = "";
    private String spatialOperation = "";
    private String sql = "";
    private String textValue = "";
    private String domainValue = "";
    private int maxRecords = 100;
    private int maxSampleRecords = 10;
    private String inputLayerLabel = null;
    private String attributeSelectionLabel = null;
    private String addToQueryExpressionLabel = null;
    private String queryExpressionLabel = null;
    private String locationToQueryLabel = null;
    private String messageLabel = null;
    private String uiMessage1 = null;
    private String uiMessage2 = null;
    private String uiMessage3 = null;
    private String uiMessage4 = null;
    private String uiMessage5 = null;
    private QueryResult currentHighlighted = null;
    private GraphicElement filterGraphics = null;
    private String m_saveQueryName = "Query";
    private String m_saveQyeryDescription = "";
    private List<IQuery> queryList = null;
    private String m_uploadFilename = null;
    private String m_uploadId = null;
    private boolean m_exportingSavedQuery = false;
    private QbPersistenceService m_persistenceService = null;
    private ResourceAdder resourceAdder = null;
    private ResourceFinder m_resourceFinder = null;
    private String _tab1 = null;
    private String _tab2 = null;
    private String _tab3 = null;
    private String _footerNoteTab1 = null;
    private String _footerNoteTab2 = null;
    private String _footerNoteTab3 = null;
    private boolean m_queryFullExtent = true;
    private Integer m_saveQueryMethod = SAVE_QUERY_REPOSITORY;
    private Integer m_loadQueryMethod = LOAD_QUERY_REPOSITORY;
    private String m_selectedQuery = null;
    private Map<Integer, String> m_saveQueryMethods = null;
    private Map<Integer, String> m_loadQueryMethods = null;
    private Map<String, String> m_queries = null;
    private IPersonalizationContext personalizationCtx = null;
    private IADFToBeanConverter m_converter;
    private IBeanToADFConverter m_beanToAdfConverter;

    // point properties
    protected String _pointMarkerParam = null;
    protected String _shapeWidth = null;
    protected String _shapeColor = null;
    protected String _pointSizeParam = null;
    protected String _pointColorParam = null;
    protected LinkedHashMap<Integer, String> _pointMarkerTypeList = null;

    // polygon properties
    protected String _polygonFillColor = null;
    protected String _fillColorParam = null;
    protected long _polygonFillInterval = 10;
    protected int _polygonFillTypeId = -1;
    protected int _polygonBoundaryWidth = -1;
    protected String _polygonBoundaryColor = null;
    protected double _fillTransparencyParam = 0.5;
    protected String _simplePolygonBoundaryType = WebSimplePolygonSymbol.SOLID;
    protected String _fillTypeParam = null;
    protected String _boundaryColorParam = null;
    protected String _boundaryWidthParam = null;

    // line properties
    protected String _lineColor = null;
    protected String _lineColorParam = null;
    protected String _lineWidth = null;
    protected String _lineWidthParam = null;
    protected int _lineTypeId = -1;
    protected String _lineTypeParam = null;
    @SuppressWarnings("unused")
    private SelectedToolDesc selectedToolDesc = SelectedToolDesc.NONE;
    private long m_renderId = System.currentTimeMillis();
    private boolean _personalizationContextSet = false;

    public QueryBuilderTask() {
        super();

        setTaskInfo(new QueryBuilderTaskInfo());
        this.taskName = TextResources.getResourceString(ResourceProps.QUERY_BUILDER_TASK);

        // initialize the radio button choices for saving queries
        m_saveQueryMethods = new LinkedHashMap<Integer, String>();
        m_saveQueryMethods.put(SAVE_QUERY_REPOSITORY,
            TextResources.getResourceString(ResourceProps.REPOSITORY));
        m_saveQueryMethods.put(SAVE_QUERY_LOCAL,
            TextResources.getResourceString(ResourceProps.LOCAL_DISK));

        // initialize the radio button choices for loading queries
        m_loadQueryMethods = new LinkedHashMap<Integer, String>();
        m_loadQueryMethods.put(LOAD_QUERY_REPOSITORY,
            TextResources.getResourceString(ResourceProps.REPOSITORY));
        m_loadQueryMethods.put(LOAD_QUERY_LOCAL,
            TextResources.getResourceString(ResourceProps.LOCAL_DISK));

        // initialize dropdown for loading existing queries
        m_queries = new LinkedHashMap<String, String>();

        this._pointMarkerTypeList = new PointMarkerMap();

        this.resourceAdder = new ResourceAdder();
    }

    public void setPersonalizationContext(IPersonalizationContext ctx) {
        personalizationCtx = ctx;

        if (personalizationCtx != null) {
            _personalizationContextSet = true;

            //refresh();
        } else {
            _personalizationContextSet = false;
        }
    }

	public void refresh() {
		try {
		    queryList = personalizationCtx.getData().getQueries();

		    Iterator it = queryList.iterator();

		    while (it.hasNext()) {
		        IQuery query = (IQuery) it.next();

		        if (query.getType().equals(IQuery.Type.FEATURE)) {
		            m_queries.put(query.getId().toString(), query.getName());
		        }
		    }
		} catch (Exception ex) {
		    _logger.error("Could not query DB for user Queries", ex);
		}
	}

	public boolean shouldRefresh () {
		return (queryList == null) || (queryList.isEmpty());
	}
	
    public boolean getPersonalizationContextSet() {
        return _personalizationContextSet;
    }

    /**
     * Sets the instance of an {@link IADFToBeanConverter} object to use
     * internally.
     */
    public void setConverter(IADFToBeanConverter converter) {
        if (converter == null) {
            throw new NullPointerException();
        }

        m_converter = converter;
    }

    /**
     * Sets the instance of an {@link IBeanToADFConverter} object to use
     * internally.
     */
    public void setBeanToAdfConverter(IBeanToADFConverter converter) {
        if (converter == null) {
            throw new NullPointerException();
        }

        m_beanToAdfConverter = converter;
    }

    public TaskInfo getTaskInfo() {
        if (this._context == null) {
            taskInfo.getTaskDescriptor().setDisabled(true);
        }

        //doSelectLayer(null);
        return this.taskInfo;
    }

    public void setTaskInfo(TaskInfo taskInfo) {
        _logger.debug("Setting task info");
        this.taskInfo = (QueryBuilderTaskInfo) taskInfo;
        super.setTaskInfo(this.taskInfo);
    }

    //Needed for symbol settings
    @SuppressWarnings("deprecation")
    protected WebSymbol getSymbol() {
        WebSimplePolygonSymbol symbol = new WebSimplePolygonSymbol();
        symbol.setAntialiasing(true);
        symbol.setFillType(getFillTypeParam());
        symbol.setFillColor(getFillColorParam());
        symbol.setFillTransparency(getFillTransparencyParam());
        symbol.setColor(getBoundaryColorParam());
        symbol.setWidth(Integer.parseInt(getBoundaryWidthParam()));
        symbol.setCapType(WebSimplePolygonSymbol.ROUND);

        return symbol;
    }

    protected WebSimpleMarkerSymbol createSymbol() {
        WebSimpleMarkerSymbol symbol = new WebSimpleMarkerSymbol();

        symbol.setColor(getPointColorParam());
        symbol.setAntialiasing(true);
        symbol.setMarkerType(Integer.parseInt(getPointMarkerParam()));
        symbol.setWidth(Integer.valueOf(getPointSizeParam()));

        return symbol;
    }

    public void setContext(WebContext context) {
        if (context != null) {
            super.setContext(context);

            this.resourceAdder.setWebContext(context);

            this.layerList = QueryBuilderTaskUtil.getLayerList(context);

            if (this.getLayer() == null) {
                Iterator<Map.Entry<String, String>> it = this.layerList.entrySet()
                                                                       .iterator();
                String flayer = null;

                if (it.hasNext()) {
                    Map.Entry<String, String> entry = (Map.Entry<String, String>) it.next();
                    flayer = (String) entry.getKey();
                    this.setLayerName(entry.getValue());
                    this.setLayer(flayer);

                    try {
                        getUpdateAttributeList(flayer);
                    } catch (Exception ex) {
                        _logger.warn("Unable to retrieve attribute list for selected layer",
                            ex);
                    }
                }
            }
        } else {
            taskInfo.getTaskDescriptor().setDisabled(true);
            _logger.warn("Task passed null WebContext, disabling");
        }
    }

    public void setResourceFinder(ResourceFinder rf) {
        this.m_resourceFinder = rf;
    }

    /**
     * Gets the maximum number of records returned by a query
     */
    public int getMaxRecords() {
        return maxRecords;
    }

    /**
     * Sets the maximum number of records returned by a query
     */
    public void setMaxRecords(int maxNumberOfRecords) {
        maxRecords = maxNumberOfRecords;
    }

    /**
     * Gets the maximum number of sample records returned by a query
     */
    public int getMaxSampleRecords() {
        return maxSampleRecords;
    }

    /**
     * Sets the maximum number of records returned by a query
     */
    public void setMaxSampleRecords(int maxNumberOfSampleRecords) {
        maxSampleRecords = maxNumberOfSampleRecords;
    }

    /**
     * Get task name
     */
    public String getTaskName() {
        return taskName;
    }

    /**
     * Set task name
     */
    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }

    /**
     * Get input layer label
     */
    public String getInputLayerLabel() {
        return this.inputLayerLabel;
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -