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

📄 filtertask.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	public void setSpatialOperation(String spatialOperation){
		this.spatialOperation = spatialOperation;
	}

	/**
	 * Get domain value
	 */
	public String getDomainValue(){
		return this.domainValue;
	}

	/**
	 * Set domain value
	 */
	public void setDomainValue(String domainValue){
		this.domainValue = domainValue;
	}

	/**
	 * Get sql where clause
	 */
	public String getSql(){
		return this.sql;
	}

	/**
	 * Set sql where clause
	 */
	public void setSql(String sql){
		this.sql = sql;
	}

	/**
	 * Get input layer list
	 */
	public Map<String, String> getInputLayerList(){
		return this.layerList;
	}
	
	/**
	 * Get Selected layer
	 */
	public String getSelectedLayer(){
		return this.selectedLayer;
	}
	
	/**
	 * Set Selected layer
	 */
	public void setSelectedLayer(String input){
		//Inform task renderer to render task
		this.taskInfo.getTaskDescriptor().setShouldRender(true);
		
		this.selectedLayer = input;
	}
	
	/**
	 * Get input layer 
	 */
	public String getInputLayer(){
		return this.inputLayer;
	}
	
	/**
	 * Set input layer 
	 */
	public void setInputLayer(String inputLayer){
		this.inputLayer = inputLayer;
	}

	/**
	 * Get spatial layer list
	 */
	public Map<String, String> getSpatialLayerList(){
		return this.spatialLayerList;
	}

	/**
	 * Get attribute list
	 */
	public Map<String, String> getAttributeList(){
		return this.attributeList;
	}

	/**
	 * Set attribute list
	 */
	public void setAttributeList(LinkedHashMap<String, String> attributeList){
		this.attributeList = attributeList;
	}

	/**
	 * Set attribute selection
	 */
	public void setAttributeSelection(String attributeSelection){
		this.attributeSelection = attributeSelection;
	}

	/**
	 * Get attribute selection
	 */
	public String getAttributeSelection(){
		return this.attributeSelection;
	}

	/**
	 * Set spatial filter selection
	 */
	public void setSpatialFilterSelection(String spatialFilterSelection){
		this.spatialFilterSelection = spatialFilterSelection;
	}

	/**
	 * Get spatial filter selection
	 */
	public String getSpatialFilterSelection(){
		return this.spatialFilterSelection;
	}

	/**
	 * Get operation list
	 */
	public Map<String, String> getOperationList(){
		try{
			LinkedHashMap<String, String> operationList = new LinkedHashMap<String, String>();
			operationList.put("=", TextResources.getResourceString(EQUAL_TO));
			operationList.put(">", TextResources.getResourceString(GREATER_THAN));
			operationList.put(">=", TextResources.getResourceString(GREATER_THAN_OR_EQUAL_TO));
			operationList.put("<", TextResources.getResourceString(LESS_THAN));
			operationList.put("<=", TextResources.getResourceString(LESS_THAN_OR_EQUAL_TO));
			operationList.put("<>", TextResources.getResourceString(NOT_EQUAL_TO));
			this.operationList = operationList;
			return this.operationList;
		}
		catch(Exception ex){
			renderExceptionMessage(ex);
			logger.error("Error retrieving operation list", ex);
			return null;
		}
	}

	/**
	 * Get spatial operation list
	 */
	public Map<String, String> getSpatialOperationList(){
		try{
			LinkedHashMap<String, String> spatialOperationList = new LinkedHashMap<String, String>();
			spatialOperationList.put("intersects", TextResources.getResourceString(INTERSECT));
			spatialOperationList.put("within", TextResources.getResourceString(WITHIN));
			this.spatialOperationList = spatialOperationList;
			return this.spatialOperationList;
		}
		catch(Exception ex){
			renderExceptionMessage(ex);
			logger.error("Error retrieving SpatialOperationList", ex);
			return null;
		}
	}
	
	/**
	 * Reset the domain value list
	 */
	public void resetDomainValueList(){
		this.domainValueList = null;
	}

	/**
	 * Get domain value list
	 */
	public Map<String, String> getDomainValueList(){
		if (this.domainValueList == null){
			this.domainValueList = new LinkedHashMap<String, String>();
			this.domainValueList.put("", TextResources.getResourceString(NO_VALUES));
		}
		return this.domainValueList;
	}

	/**
	 * Update list event
	 */
	public void updateList(TaskEvent event){
		try{
			//Inform task renderer to render task
			this.taskInfo.getTaskDescriptor().setShouldRender(true);
			
			this.layerList = FilterUtil.getLayerList(this.context);
			this.context.refresh();
		}
		catch(Exception ex){
			renderExceptionMessage(ex);
			logger.error("Unable to update list", ex);
		}
	}

	private void returnErrorMessage(){
		ArrayList<FilterResult> results = new ArrayList<FilterResult>();
		FilterResult qbRes = new FilterResult(this.context);
		qbRes.setResultUrl("${table-result-error(" + TextResources.getResourceString(ERROR_MESSAGE) + ")(" + QUERY_RESULT + ")}");
		results.add(qbRes);
		this.context.getWebResults().addResultsWithActionMap("${table-result-error(" + TextResources.getResourceString(ERROR_MESSAGE) + ")(" + QUERY_RESULT + ")}", results, null, null, null);
	}
	
	/**
	 * Performs the filtering on the selected layer
	 * @param event
	 * 		TaskEvent reference
	 */
	public void filterLayer(TaskEvent event) {
		//Inform task renderer to render task
		this.taskInfo.getTaskDescriptor().setShouldRender(true);
		
		doFilter(event.getWebContext(), this.getSql());
	}
	
	/**
	 * Clears all filtering on layer
	 * @param event
	 * 		TaskEvent reference
	 */
	public void clearLayer(TaskEvent event) {
		logger.debug("Clearing Layer....");
		
		//Inform task renderer to render task
		this.taskInfo.getTaskDescriptor().setShouldRender(true);
		
		// send in an empty string to clear the filter
		doFilter(event.getWebContext(), "");
	}
	
	/**
	 * Get sample value event
	 */
	public void sampleValues(TaskEvent event){
		
		//Inform task renderer to render task
		this.taskInfo.getTaskDescriptor().setShouldRender(true);
		
		setSampleValues();
	}
	
	/**
	 * Update the sample value list
	 */
	public void setSampleValues(){
		try{
			String layer = this.getLayer();
			String[] layerInfo = layer.split("!");
			Map resources = this.context.getResources();								
			String id = layerInfo[0];
			Object resource = resources.get(id);
			String[] attrInfo = this.getAttribute().split("!");
			WebQuery webQuery = (WebQuery)this.context.getAttribute("query");
			String layerName = FilterUtil.findLayerName(resource, layerInfo[1]);
			String attrName = attrInfo[0];
			this.domainValueList = FilterUtil.getSampleList(webQuery, layerName, attrName);
			Map<String, String> list = this.getDomainValueList();
			
			for (Map.Entry<String, String> mapList : list.entrySet())
			{
			  Object value = mapList.getValue();
			  this.setDomainValue((String)value);
			  String val = this.getDomainValue();
			  if (!(val.equals(" "))){
			  	break;
			  }
			}
		}
		catch(Exception ex){
			renderExceptionMessage(ex);
			logger.error("Unable to set sample values", ex);
		}

		this.context.refresh();
	}

	/**
	 * Filter event
	 */
	
	private void doFilter(WebContext webContext, String filterClause) {
		try {
			WebQuery webQuery = webContext.getWebQuery();
			
			if (this.webFilter == null || webQuery == null) {
				renderResourceMessage("Filter could not be performed");
				logger.error("WebContext returned null for WebFilter, filter can not be performed");
				return;
			}
			
			//Get layer ID and resource name
			final int resourceIdx = 0;
			final int layerIdIdx = 1;
			String layer = this.getLayer();
			String[] layerInfo = layer.split("!");			
			String id = layerInfo[resourceIdx];
			Map resourcesHashMap =  this.context.getResources();	
			Object resourceName = resourcesHashMap.get(id);
			GISResource gisResource = (GISResource) resourceName;
			String layerId = FilterUtil.findLayerName(resourceName, layerInfo[layerIdIdx]);	
			if (layerId == null) {
				renderResourceMessage(ResourceProps.ERROR_LAYER_NOT_FOUND);
				logger.error("Could not find layer name, query could not be performed");
				returnErrorMessage();
				return;
			}

			//Get the layer info for the desired service
			List<WebLayerInfo> lstWebLayerInfos = webQuery.getQueryLayers();
			int iLayerId = Integer.parseInt(layerInfo[layerIdIdx]);
			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");
				returnErrorMessage();
			}
			else {
				if (this.getSql() != null ){//&& this.getSql().trim().length() > 0) {
					webFilter.filter(queryWebLayerInfo, filterClause);
					
					// Set the _layerMap for Personalization
					if (queryWebLayerInfo.getResource() instanceof AGSMapResource) {
			    		AGSMapResource agsMapResource = (AGSMapResource)queryWebLayerInfo.getResource();
						AGSMapFunctionality agsMapFunc = (AGSMapFunctionality)(agsMapResource).getFunctionality("map");
						MapLayerInfo mapLayer = agsMapFunc.getLayerInfo(queryWebLayerInfo.getId());
					
						if (!filterClause.equals("")) {
					    	_layerMap.put(mapLayer, filterClause);
						} 
						else {
					    	_layerMap.remove(mapLayer);
						}
			    	}
			    	else if (queryWebLayerInfo.getResource() instanceof AGSLocalMapResource) {
			    		AGSLocalMapResource agsLocalMapResource = (AGSLocalMapResource)queryWebLayerInfo.getResource();
						AGSMapFunctionality agsMapFunc = (AGSMapFunctionality)(agsLocalMapResource).getFunctionality("map");
						MapLayerInfo mapLayer = agsMapFunc.getLayerInfo(queryWebLayerInfo.getId());
						
						if (!filterClause.equals("")) {
							_layerMap.put(mapLayer, filterClause);
						}
						else{
					    	_layerMap.remove(mapLayer);
						}
			    	}
			    	else {
			    		logger.error("Unable to filter on selected resource, resource type not supported");
			    		throw new FilterNotSupportedOnServiceTypeException("Unable to filter on selected resource, resource type not supported");
			    	}
					
					// Set the FilterExpression attribute in personalization context
					if (_personalCtx != null) {
					    if (_personalCtx.getAttribute("FilterExpression")== null) {
					    	_personalCtx.setAttribute("FilterExpression", _layerMap);
					    }
					}
					else{
						returnErrorMessage();
					}
					
				}
			}
		}
		catch(Exception e) {
			renderExceptionMessage(e);
			logger.error("Unable to do query", e);
			returnErrorMessage();
		}
	}

	private LinkedHashMap<String, String> updateSpatialLayerList(LinkedHashMap<String, String> layerList, String layerKey){
		try{
			LinkedHashMap<String, String> spatialLayerList = (LinkedHashMap<String, String>)layerList.clone();
			spatialLayerList.remove(layerKey);
			return spatialLayerList;
		}
		catch(Exception ex){			
			renderExceptionMessage(ex);
			logger.error("Error apdating Spatial Layer list", ex);
			return null;
		}
	}

	private LinkedHashMap sortHashMapByValues(HashMap passedMap, boolean ascending){
		try{
			// no strong type defined for the sorting list, Collections.sort() won't take it.
			List mapKeys = new ArrayList(passedMap.keySet());
			List mapValues = new ArrayList(passedMap.values());
			Collections.sort(mapValues);
			Collections.sort(mapKeys);
	
			if (!ascending) Collections.reverse(mapValues);
			LinkedHashMap<Object, Object> someMap = new LinkedHashMap();
			
			Iterator valueIt = mapValues.iterator();
			while (valueIt.hasNext()){
				Object val = valueIt.next();
				Iterator keyIt = mapKeys.iterator();
				while (keyIt.hasNext()){
					Object key = keyIt.next();
					if (passedMap.get(key).toString().equals(val.toString())){
						passedMap.remove(key);
						mapKeys.remove(key);
						someMap.put(key, val);
						break;
					}
				}
			}
			return someMap;
		}
		catch(Exception ex){
			renderExceptionMessage(ex);
			logger.error("Error creating hashmap", ex);
			return null;
		}
	} 

	/**
	 * Update the attribute list for the selected layer
	 * @param layer
	 */
	public void getUpdateAttributeList(String layer){
		try{
			String[] layerInfo = layer.split("!");
			Map resources = this.context.getResources();								
			String id = layerInfo[0];
			Object resource = resources.get(id);
			
			if (resource instanceof AGSMapResource){
				AGSInternetProxy agsProxy = new AGSInternetProxy();
				this.attributeList = agsProxy.getAgsFieldList(resource, id, Integer.parseInt(layerInfo[1]));
			}
			
			//Some layers do not support attributes. Under this condition,
			//this.attributeList is set to null
			if (this.attributeList != null) {
				this.attributeList = this.sortHashMapByValues(this.attributeList, true);
			}
			
			if (this.layerList != null){
				this.spatialLayerList = updateSpatialLayerList(this.layerList, getLayer());
			}
		}
		catch(Exception e){
			logger.error("Unable to get updated attribute list", e);
			renderExceptionMessage(e);
		}
	}

	/**
	 * Update field list event
	 */
	public void doSelectLayer(){
		getUpdateAttributeList(this.getLayer());
	}

	/**
	 * Get current highlighted feature
	 */
	public QueryResult getCurrentHighlighted() {
		return currentHighlighted;
	}

	/**
	 * Set current highlighted feature
	 */
	public void setCurrentHighlighted(QueryResult currentHighlighted)
	{
		this.currentHighlighted = currentHighlighted;
	}

	/**
	 * Clears all queries
	 * @param event
	 */
	public void clearQuery(TaskEvent event){
		//Inform task renderer to render task
		this.taskInfo.getTaskDescriptor().setShouldRender(true);
		
		doClearQuery();
	}
	
	private void doClearQuery(){
		try{
			this.context.getWebQuery().clearGraphics();
			this.context.getWebResults().clearAll();
		} 
		catch(Exception ex){
			renderExceptionMessage(ex);
			logger.error("Unable to clear Query", ex);
		}
	}

	
}

⌨️ 快捷键说明

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