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

📄 querybuildertask.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }

    public void setPointSizeParam(String pointSizeParam) {
        this._pointSizeParam = pointSizeParam;
    }

    public LinkedHashMap<Integer, String> getPointMarkerTypeList() {
        return _pointMarkerTypeList;
    }

    public void setPointMarkerTypeList(
        LinkedHashMap<Integer, String> pointMarkerTypeList) {
        this._pointMarkerTypeList = pointMarkerTypeList;
    }

    public String getFillTypeParam() {
        return this._fillTypeParam;
    }

    public void setFillTypeParam(String fillTypeParam) {
        this._fillTypeParam = fillTypeParam;
    }

    public String getFillColorParam() {
        return this._fillColorParam;
    }

    public void setFillColorParam(String color) {
        this._fillColorParam = color;
    }

    public double getFillTransparencyParam() {
        return this._fillTransparencyParam;
    }

    public void setFillTransparencyParam(double transparency) {
        this._fillTransparencyParam = transparency;
    }

    public String getBoundaryColorParam() {
        return this._boundaryColorParam;
    }

    public void setBoundaryColorParam(String boundaryColorParam) {
        this._boundaryColorParam = boundaryColorParam;
    }

    public String getBoundaryWidthParam() {
        return this._boundaryWidthParam;
    }

    public void setBoundaryWidthParam(String boundaryWidthParam) {
        this._boundaryWidthParam = boundaryWidthParam;
    }

    public String getLineTypeParam() {
        return this._lineTypeParam;
    }

    public void setLineTypeParam(String lineTypeParam) {
        this._lineTypeParam = lineTypeParam;
    }

    public String getLineColorParam() {
        return this._lineColorParam;
    }

    public void setLineColorParam(String lineColorParam) {
        this._lineColorParam = lineColorParam;
    }

    public String getLineWidthParam() {
        return this._lineWidthParam;
    }

    public void setLineWidthParam(String lineWidthParam) {
        this._lineWidthParam = lineWidthParam;
    }

    public boolean getExportingSavedQuery() {
        return m_exportingSavedQuery;
    }

    public void setExportingSavedQuery(boolean exporting) {
        m_exportingSavedQuery = exporting;
    }

    /**
     * Update layer list task event
     */
    public void updateList(TaskEvent event) {
        _logger.info("Updating layer list");
        requestTaskRender();

        try {
            this.uiMessage5 = "";
            this.layerList = QueryBuilderTaskUtil.getLayerList(this._context);
        } catch (Exception ex) {
            renderExceptionMessage(ex);
            _logger.error("Unable to update layer list", ex);
        }
    }

    /**
    * Sets a flag that gets rendered to the client indicating
    * that the user has selected to export the current
    * configured query.
    *
    * @param event ADF {@link TaskEvent}.
    */
    public void exportQuery(TaskEvent event) {
        requestTaskRender();
        m_exportingSavedQuery = true;
    }

    /**
     * This event is triggered when a new map is created.
     * Implements the method from IMapCompositionEventObserver
     * interface.
     *
     * @param  event  MapCompositionEvent object
     * @return      void
     */
    public void created(MapCompositionEvent event) {
        m_exportingSavedQuery = false;
        // update the layer list
        updateList(null);
        // clear the previous query expression
        this.sql = "";
        resetDomainValueList();
        setRenderId(System.currentTimeMillis());
    }

    /**
     * This event is triggered when a map is deleted.
     * Implements the method from IMapCompositionEventObserver
     * interface.
     *
     * @param  event  MapCompositionEvent object
     * @return      void
     */
    public void deleted(MapCompositionEvent event) {
    }

    /**
     * This event is triggered when a map is opened.
     * Implements the method from IMapCompositionEventObserver
     * interface.
     *
     * @param  event  MapCompositionEvent object
     * @return      void
     */
    public void opened(MapCompositionEvent event) {
        m_exportingSavedQuery = false;

        // update the layer list
        updateList(null);
        // clear the previous query expression
        this.sql = "";
        resetDomainValueList();
        setRenderId(System.currentTimeMillis());
    }

    /**
     * This event is triggered when a map is saved.
     * Implements the method from IMapCompositionEventObserver
     * interface.
     *
     * @param  event  MapCompositionEvent object
     * @return      void
     */
    public void saved(MapCompositionEvent event) {
    }

    /**
     * Performs the query on the specified layer
     * @throws Exception
     */
    private void queryLayer() throws Exception {
        m_exportingSavedQuery = false;

        WebQuery webQuery = _context.getWebQuery();
        _logger.debug("Clearing WebQuery graphics");
        
        //Get layer ID and resource name
        String layer = this.getLayer();
        SelectedLayerStringParser lsp = new SelectedLayerStringParser(layer, '!', _context);
        String layerName = lsp.getSelectedLayerName();
        String resourceId = lsp.getSelectedResourceId();
        GISResource gisResource = _context.getResources().get(resourceId);

        if (layerName == null) {
            renderResourceMessage(ResourceProps.ERROR_LAYER_NOT_FOUND);
            _logger.error("Could not find layer name, query could not be performed");
            return;
        }

        QueryBuilderCriteria qbc = new QueryBuilderCriteria();
        String layerId = QueryBuilderUtil.findLayerIndex(gisResource, layerName);
        qbc.setLayerId(layerId);

        QueryBuilder queryBuilder = new QueryBuilder(webQuery);

        if (getSpatialFilterSelection().equalsIgnoreCase("graphics") && (filterGraphics != null) && (m_queryFullExtent == false)) {
            qbc.setWebGeometry(filterGraphics.getGeometry());
        }

        if ((this.getSql() != null) && (this.getSql().trim().length() > 0)) {
            qbc.setWhereClause(this.getSql());
        } else {
            qbc.setWhereClause(null);
        }

        //Get the layer info for the desired service
        qbc.setMaxRecordCount(this.maxRecords);

        List<WebLayerInfo> lstQueryLayers = new ArrayList<WebLayerInfo>();
        List<WebLayerInfo> lstWebLayerInfos = webQuery.getQueryLayers();
        int iLayerId = Integer.parseInt(layerId);
        WebLayerInfo queryWebLayerInfo = WebLayerInfoUtil.getWebLayerInfo(lstWebLayerInfos, gisResource, iLayerId);

        if (queryWebLayerInfo == null) {
            _logger.warn("Could not aquire WebLayerInfo for layer to query, sending all layer info to query request");
            lstQueryLayers = lstWebLayerInfos;
        
        } else {
            lstQueryLayers.add(queryWebLayerInfo);
        }

        List searchResults = queryBuilder.doQuery(qbc, lstQueryLayers, gisResource);

        if (searchResults == null) {
            renderResourceMessage(ResourceProps.ERROR_QUERY_RETURNED_NULL);
            _logger.error("Query performed and search results were null (ADF Bug?)");
            return;
        }

        _logger.debug("Selecting query results");
        this.highlightResults(searchResults);

        _logger.debug("Adding results to WebResults");
        _context.getWebResults().addResultsWithActionMap("Query Builder", searchResults, "getName", "getDetails", _actions, "clearGraphic");

        if (filterGraphics != null) {
            _context.getWebGraphics().removeGraphics(filterGraphics);
            //filterGraphics = null;
        }

        _logger.debug("Refreshing web context");
        _context.refresh();
    }

    /**
    * Sets the {@link QbPersistenceService} reference for storing and
    * loading queries.
    *
    * @param service The {@link QbPersistenceService} reference.
    */
    public void setPersistenceService(QbPersistenceService service) {
        if (service == null) {
            throw new NullPointerException("persistence service cannot be null");
        }

        m_persistenceService = service;
    }

    /**
     * Gets the {@link QbPersistenceService} reference for storing and
    * loading queries.
    *
     * @return {@link QbPersistenceService} reference.
     */
    public QbPersistenceService getPersistenceService() {
        return m_persistenceService;
    }

    /**
     * Saves the configured query to it's XML representation by delegating to
     * {@link QbPersistenceService#saveToXml(QbPersistenceObject)}.
     *
     * @param context Reference to the ADF {@link WebContext} object that is used
     *                         for getting the current map extent.
     * @return  XML representation of the saved query.
     * @throws NullPointerException Thrown if the <code>context</code> argument is
     *                         <code>null</code>.
     * @throws IllegalStateException Thrown if the {@link QbPersistenceService} member
     *                         has not been set.
     */
    public String saveQueryToString(WebContext context) {
        String strQuery = null;
        QbPersistenceObject obj = null;

        if (context == null) {
            throw new NullPointerException("WebContext cannot be null - unable to export query.");
        }

        if (m_persistenceService == null) {
            throw new IllegalStateException("persistence service cannot be null - unable to load saved queries");
        }

        try {
            obj = createPersistenceObject(context);
            strQuery = m_persistenceService.saveToXml(obj);
        
        } catch (PersonalizationException ex) {
            _logger.warn("PersonalizationException occurred saving query - unable to export query", ex);
        }

        return strQuery;
    }

    /**
     * Perform attribute query task event
     */
    public void query(TaskEvent event) {
        _logger.info("Performing attribute query");
        requestTaskRender();

        event.getWebContext().getWebQuery().clearGraphics();
        event.getWebContext().getWebResults().clearAll();
		
        m_queryFullExtent = true;
        m_exportingSavedQuery = false;
        
        try {
            this.uiMessage5 = "";
            queryLayer();
          
        } catch (Exception ex) {
            _logger.error("Unable to perform attribute query", ex);
            renderResourceMessage("querybuildertask.msg.error.couldNotPerformQuery", ex.getCause());
        }
    }

    /**
     * Get sample value event
     */
    public void sampleValues(TaskEvent event) {
        _logger.info("Getting layer attribute sample values");
        requestTaskRender();

        try {
            String[] attrInfo = this.getAttribute().split("!");
            this.uiMessage5 = "";

            WebQuery wQuery = _context.getWebQuery();
            SelectedLayerStringParser lsp = new SelectedLayerStringParser(getLayer(), '!', _context);
            String layerName = lsp.getSelectedLayerName();
            String whereClause = "1 = 1";

            if (lsp.isWfsResource(_context)) {
                whereClause = "";
            }

            this.domainValueList = QueryBuilderUtil.getSampleList(wQuery, layerName, attrInfo[0], whereClause, this.maxSampleRecords);

            if (this.domainValueList == null) {
                renderResourceMessage(ResourceProps.UIMESSAGE5);
            }
            
        } catch (Exception ex) {
            renderExceptionMessage(ex);
            _logger.error("Unable to retrieve sample values", ex);
        }
    }

    private LinkedHashMap<String, String> updateSpatialLayerList(
        LinkedHashMap<String, String> layerList, String layerKey) {
        LinkedHashMap<String, String> spatialLayerList = (LinkedHashMap<String, String>) layerList.clone();
        spatialLayerList.remove(layerKey);

        return spatialLayerList;
    }

    private void getUpdateAttributeList(String layer) throws Exception {
        if ((layer == null) || (layer.length() == 0)) {
            return;
        }

        String[] layerInfo = layer.split("!");
        LinkedHashMap<String, GISResource> resources = (LinkedHashMap<String, GISResource>) this._context.getResources();
        String gisResourceId = layerInfo[0];
        int layerId = Integer.parseInt(layerInfo[1]);
        Object resource = resources.get(gisResourceId);

        if (resource instanceof AIMSMapResource) {
            this.attributeList = QueryBuilderTaskAimsUtil.getAimsFieldList(resource, gisResourceId, layerId);
        
        } else if (resource instanceof AGSMapResource) {
            this.attributeList = QueryBuilderTaskAgsUtil.getAgsFieldList(resource, gisResourceId, layerId);
        
        } else if (resource instanceof WFSMapResource) {
            WFSMapResource wfsMapResource = (WFSMapResource) resource;
            this.attributeList = QueryBuilderTaskWfsUtil.getWfsFieldList(wfsMapResource, layerId);

⌨️ 快捷键说明

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