📄 querybuildertask.java
字号:
} else {
_logger.error("layer null or empty, can not obtain attribute list");
throw new Exception("layer null or empty, can not obtain attribute list");
}
//Some layers do not support attributes. Under this condition,
//this.attributeList is set to null
if (this.attributeList != null) {
HashMapSorter hms = new HashMapSorter();
this.attributeList = hms.sort(this.attributeList, true);
}
if (this.layerList != null) {
this.spatialLayerList = updateSpatialLayerList(this.layerList, getLayer());
}
}
/**
* Update field list event
*/
public void doSelectLayer(TaskEvent event) {
_logger.info("Updating task based on user selected layer");
requestTaskRender();
try {
getUpdateAttributeList(getLayer());
} catch (Exception ex) {
renderExceptionMessage(ex);
_logger.error("Unable populate attribute list based on user selected layer", ex);
}
}
public QueryResult getCurrentHighlighted() {
return currentHighlighted;
}
public void setCurrentHighlighted(QueryResult currentHighlighted) {
this.currentHighlighted = currentHighlighted;
}
/**
* Clears any and all queries
* @param {@link TaskEvent} reference
*/
public void clearQuery(TaskEvent event) {
_logger.info("Clearing selections");
requestTaskRender();
m_exportingSavedQuery = false;
try {
this.uiMessage5 = "";
// delete any previously drawn spatial filters
mgResource.deleteAllGraphicFeatures();
// disable Query Selection button since no spatial filters are available
enableQuerySelectionBtn(false);
this.filterGraphics = null;
event.getWebContext().refresh();
} catch (Exception ex) {
renderExceptionMessage(ex);
_logger.error("Unable to clear selections", ex);
}
}
/**
* Performs query at specified location
* @param {@link TaskEvent} reference
*/
public void queryLocation(TaskEvent event) {
_logger.info("Querying Specified Location");
requestTaskRender();
event.getWebContext().getWebQuery().clearGraphics();
event.getWebContext().getWebResults().clearAll();
m_exportingSavedQuery = false;
m_queryFullExtent = false;
try {
queryLayer();
} catch (Exception ex) {
renderResourceMessage("querybuildertask.msg.error.couldNotPerformQuery", ex);
_logger.error("Unable to query specified location", ex);
}
}
/**
* Performs a save on the configured query by delegating
* to {@link QbPersistenceService#save(QbPersistenceObject)}.
*
* @param event ADF {@link TaskEvent}.
*/
public void saveQuery(TaskEvent event) {
try {
_logger.info("Saving Query");
requestTaskRender();
QbPersistenceObject obj = null;
m_exportingSavedQuery = false;
if (m_persistenceService == null) {
throw new IllegalStateException("persistence service not set");
}
obj = createPersistenceObject(event.getWebContext());
try {
m_persistenceService.save(obj);
// refresh the list in load task
queryList = m_persistenceService.getSavedQueries();
for (IQuery query : queryList) {
if (query.getType().equals(IQuery.Type.FEATURE)) {
m_queries.put(query.getId().toString(), query.getName());
}
}
} catch (PersonalizationException ex) {
_logger.error("PersonalizationException occurred saving query", ex);
throw ex;
}
renderResourceMessage("querybuildertask.ui.msg.querySaveSuccess", messageType.SUCCESS);
} catch (Exception ex) {
renderExceptionMessage(ex);
_logger.error("Unable to save query", ex);
}
}
/**
* Loads the <code>obj</code> into the task's getter and
* setters.
*
* @param obj {@link QbPersistenceObject} to load.
*
* @throws NullPointerException Thrown if the <code>context</code> argument
* is <code>null</code>.
*/
private void loadQuery(WebContext webContext, QbPersistenceObject obj) {
try {
m_exportingSavedQuery = false;
_logger.info("Setting Query properties");
loadResourcesNotInMap(webContext, obj);
// Set the where clause in the GUI
this.sql = obj.getAttribute(QbPersistenceObject.QUERY_WHERE_CLAUSE_KEY);
// delete any previously drawn spatial filters
mgResource.deleteAllGraphicFeatures();
if (obj.getPolygonGeom() != null) {
drawPoly(obj.getPolygonGeom());
// set the currently selected tool
selectedToolDesc = SelectedToolDesc.RECT;
} else if (obj.getPointGeom() != null) {
drawPoint(obj.getPointGeom());
// set the currently selected tool
selectedToolDesc = SelectedToolDesc.POINT;
}
// update the layers in the list
updateList(null);
// set the layer
setLayerFromName(obj);
// set the query name in the save query tab
this.setSaveQueryName(obj.getAttribute(QbPersistenceObject.QUERY_NAME_KEY));
// set the query description in the save query tab
this.setSaveQueryDescription(obj.getAttribute(QbPersistenceObject.QUERY_DESCRIPTION_KEY));
// refresh
this._context.refresh();
} catch (Exception ex) {
_logger.error("Unable to set query properties", ex);
renderExceptionMessage(ex);
}
}
/**
* Used to set the selected layer given a layer name rather than the layer key. This
* is used when loading a query because the layer key can't be saved when saving the
* query because it changes
* @param obj QbPersistenceObject reference
*/
private void setLayerFromName(QbPersistenceObject obj) {
// get the layer name
String layerName = obj.getAttribute(QbPersistenceObject.QUERY_LAYERNAME_KEY);
Iterator<String> iter = layerList.keySet().iterator();
while (iter.hasNext()) {
String layer = (String) iter.next();
String name = layerList.get(layer);
if (layerName.equals(name)) {
this.setLayer(layer);
return;
}
}
}
/**
* Performs a load of the selected query by delegating to
* {@link QbPersistenceService#retrieve(UUID)}.
*
* @param event ADF {@link TaskEvent}.
*/
public void loadQuery(TaskEvent event) {
_logger.info("Loading Query");
requestTaskRender();
QbPersistenceObject obj = null;
UUID uuid = null;
m_exportingSavedQuery = false;
uuid = UUID.fromString(getSelectedQuery());
try {
obj = m_persistenceService.retrieve(uuid);
if (obj == null) {
_logger.warn("Unable to load query with ID: " + uuid.toString());
return;
}
loadQuery(event.getWebContext(), obj);
} catch (PersonalizationException ex) {
_logger.warn("PersonalizationException occurred loading query", ex);
renderExceptionMessage(ex);
}
}
/**
* Checks to determine if resource(s) in {@link QbPersistenceObject}
* are currently loaded on the map. If the resource isn't currently loaded,
* this wil attempt to load the resource.
* @param obj {@link QbPersistenceObject} reference
* @return boolean - true if Resource is already loaded, false
* otherwise
*/
private boolean loadResourcesNotInMap(WebContext webContext,
QbPersistenceObject obj) throws Exception {
boolean loaded = true;
MapServiceList list = obj.getMapServiceList();
if (list == null) {
_logger.error("MapServiceList is null");
return false;
}
List msItemList = list.getMapServiceItem();
Iterator it = msItemList.iterator();
//Get the map resources
LinkedHashMap<String, GISResource> resources = (LinkedHashMap<String, GISResource>) webContext.getResources();
while (it.hasNext()) {
MapServiceItemType msItemType = (MapServiceItemType) it.next();
if (msItemType != null) {
if (msItemType.getAgsInternetService() != null) {
AgsInternetServiceType agsIntType = msItemType.getAgsInternetService();
String url = agsIntType.getEndPointUrl();
loaded = false;
AGSMapResource agsMapResource = m_resourceFinder.getAGSMapResourceByLayerName(webContext, resources, obj.getAttribute(QbPersistenceObject.QUERY_LAYERNAME_KEY));
if ((agsMapResource != null) && agsMapResource.getEndPointURL().equals(url)) {
loaded = true;
}
if (!loaded) {
// Didn't find the resource, try to load it
loadGISResource(agsIntType);
}
} else if (msItemType.getAgsLocalService() != null) {
AgsLocalServiceType agsLocalType = msItemType.getAgsLocalService();
HostList hostList = agsLocalType.getHostList();
List<String> _hostList = hostList.getHost();
loaded = false;
AGSMapResource agsMapResource = m_resourceFinder.getAGSMapResourceByLayerName(webContext, resources, obj.getAttribute(QbPersistenceObject.QUERY_LAYERNAME_KEY));
if ((agsMapResource != null) && agsMapResource instanceof AGSLocalMapResource) {
AGSLocalMapResource agsLocal = (AGSLocalMapResource) agsMapResource;
for (String hostname : _hostList) {
for (String hosts : agsLocal.getHosts()) {
if (hostname.equals(hosts)) {
loaded = true;
}
}
}
}
if (!loaded) {
// Didn't find the resource, try to load it
loadGISResource(agsLocalType);
}
} else if (msItemType.getArcImsInternetService() != null) {
loaded = false;
AIMSMapResource aimsMapResource = m_resourceFinder.getAIMSMapResourceByLayerName(webContext, resources, obj.getAttribute(QbPersistenceObject.QUERY_LAYERNAME_KEY));
if (aimsMapResource != null) {
loaded = true;
}
if (!loaded) {
// Didn't find the resource, try to load it
loadGISResource(msItemType.getArcImsInternetService());
}
} else if (msItemType.getWfsService() != null) {
//TODO: We shouldn't propagating this code pattern, but with limited schedule,
// this will just need to be refactored on other milestone
loaded = false;
WFSMapResource wfsMapResource = m_resourceFinder.getWFSMapResource(webContext, resources, obj.getAttribute(QbPersistenceObject.QUERY_LAYERNAME_KEY));
if (wfsMapResource != null) {
loaded = true;
}
if (!loaded) {
loadGISResource(msItemType.getWfsService());
}
}
}
}
_context.refresh();
return true;
}
/**
* Loads a resource provided the {@link MapServiceType}
* @param mapSvcType {@link MapServiceType} reference
* @return boolean true if loaded, otherwise false
*/
private boolean loadGISResource(MapServiceType mapSvcType) {
GISResource gisRes = null;
if (mapSvcType instanceof AgsInternetServiceType) {
gisRes = m_beanToAdfConverter.createAGSMapResource((AgsInternetServiceType) mapSvcType);
} else if (mapSvcType instanceof AgsLocalServiceType) {
gisRes = m_beanToAdfConverter.createAGSLocalMapResource((AgsLocalServiceType) mapSvcType);
} else if (mapSvcType instanceof ArcImsInternetServiceType) {
gisRes = m_beanToAdfConverter.createAIMSMapResource((ArcImsInternetServiceType) mapSvcType);
} else if (mapSvcType instanceof ArcImsTcpServiceType) {
gisRes = m_beanToAdfConverter.createAIMSMapResource((ArcImsTcpServiceType) mapSvcType);
} else if (mapSvcType instanceof WfsServiceType) {
gisRes = m_beanToAdfConverter.createWFSMapResource((WfsServiceType) mapSvcType);
}
if (gisRes == null) {
_logger.error("Could not load GIS Resource");
return false;
}
_context.addResource(UUID.randomUUID().toString(), gisRes);
return true;
}
/**
* Performs an import on the uploaded saved query which
* is stored in session. The upload ID is retrieved by
* {@link #getUploadId()}. This method will then delegate to
* {@link #loadQuery(QbPersistenceObject)}.
*
* @param event ADF {@link TaskEvent}.
*/
public void importQuery(TaskEvent event) {
FacesContext fc = null;
String strData = null;
QbPersistenceObject obj = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -