📄 cswsearchtaskbean.java
字号:
//TODO: Use the ErrorProducer to output a user
// friendly resource file based error message
// that an error encountered interfacing with the
// personalization service.
_logger.warn(
"PersonalizationException occurred deleting query with ID: " +
uuid.toString(), ex);
throw ex;
}
} catch (Exception ex) {
_logger.error("Could not delete query", ex);
renderExceptionMessage(ex);
}
}
/**
* Gets the description of the saved query.
*
* @return {@link String} saved query description.
*/
public String getSaveQueryDescription() {
return m_saveQueryDescription;
}
/**
* Sets the description of the saved query.
*
* @param description {@link String} saved query description.
*/
public void setSaveQueryDescription(String description) {
m_saveQueryDescription = description;
}
/**
* Performs a load of the selected query by delegating to
* {@link CswPersistenceService#retrieve(UUID)}.
*
* @param event ADF {@link TaskEvent}.
*/
public void loadQuery(TaskEvent event) {
try {
CswPersistenceObject obj = null;
UUID uuid = null;
requestTaskRender();
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) {
//TODO: Use the ErrorProducer to output a user
// friendly resource file based error message
// that an error encountered interfacing with the
// personalization service.
_logger.warn("PersonalizationException occurred loading query",
ex);
throw ex;
}
} catch (Exception ex) {
_logger.error("Could not load query", ex);
renderExceptionMessage(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;
}
/**
* 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(WebContext, CswPersistenceObject)}.
*
* @param event ADF {@link TaskEvent}.
*/
public void importQuery(TaskEvent event) {
try {
FacesContext fc = null;
byte[] data = null;
String strData = null;
CswPersistenceObject obj = null;
requestTaskRender();
m_exportingSavedQuery = false;
if (m_persistenceService == null) {
throw new IllegalStateException("persistence service not set");
}
fc = FacesContext.getCurrentInstance();
data = (byte[]) fc.getExternalContext().getSessionMap()
.get(getUploadId());
strData = new String(data);
if ((strData == null) || (strData.length() <= 0)) {
_logger.warn(
"Invalid query xml - cannot import saved CS/W query");
return;
}
_logger.debug("Importing query using uploaded data: " + strData);
try {
obj = m_persistenceService.retrieveFromXml(strData);
loadQuery(event.getWebContext(), obj);
} catch (PersonalizationException ex) {
_logger.warn("PersonalizationException occurred loading CS/W query from xml",
ex);
throw ex;
}
} catch (Exception ex) {
_logger.error("Could not import query", ex);
renderExceptionMessage(ex);
}
}
/**
* Performs a search on the selected CS/W service by
* delegating to {@link #performCSWFind(TaskEvent)}.
*
* @param event ADF {@link TaskEvent}.
*/
public void find(TaskEvent event) {
try {
performCSWFind(event);
} catch (Exception ex) {
_logger.error("Could not perform CSW find", ex);
renderExceptionMessage(ex);
}
}
/**
* Performs a search on the selected CS/W service which is retrieved
* from {@link #getSelectCatalog()}.
*
* <p>
* All the search criteria fields will be gathered and configured to create
* a {@link Map} of search properties. This method will then delegate to
* {@link IMetadataCatalog#lookup(Map)} which returns a {@link List} of
* {@link IMetadataDocument}. This list will then be used to populate the
* {@link WebResults}.
* </p>
*
* @param event ADF {@link TaskEvent}.
*/
public void performCSWFind(TaskEvent event) {
Map<String, String> actions = null;
WebResults wResults = null;
ResultNode rootNode = null;
IMetadataCatalog catalog = null;
Map<String, Object> props = null;
List<IMetadataDocument> records = null;
BasicMetadataExporter basicExporter = null;
CswResultDescriptor desc = null;
requestTaskRender();
m_exportingSavedQuery = false;
// update the GUI
if (getDataCategorySelectAll()) {
m_taskInfo.disableDataCategories();
} else {
m_taskInfo.enableDataCategories();
}
// clear graphics for new search
event.getWebContext().getWebQuery().clearGraphics();
props = new HashMap<String, Object>();
catalog = m_metadataContext.getCatalogById(m_selectCatalog);
props.put("numRecords", getMaxFeaturesPerSearch());
props.put("searchTerm", getSearchTerm());
// add the advanced search options
if (m_useAdvancedQuery) {
props.put("liveOnly", getLiveDataOrMaps());
if (getQueryOverlappingView()) {
double minx;
double miny;
double maxx;
double maxy;
minx = event.getWebContext().getWebMap().getCurrentExtent()
.getMinX();
miny = event.getWebContext().getWebMap().getCurrentExtent()
.getMinY();
maxx = event.getWebContext().getWebMap().getCurrentExtent()
.getMaxX();
maxy = event.getWebContext().getWebMap().getCurrentExtent()
.getMaxY();
props.put("extent.minx", minx);
props.put("extent.miny", miny);
props.put("extent.maxx", maxx);
props.put("extent.maxy", maxy);
props.put("extent.type",
CswSearchCriteria.GEOMETRY_SEARCH_OVERLAPS);
}
if (m_useDataCategories) {
// comma delimited list of topic categories
String cats = "";
if (getAgricultureDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_FARMING + ",");
}
if (getBiologyDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_BIOTA + ",");
}
if (getAdminDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_BOUNDARIES + ",");
}
if (getAtmosphericDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_CLIMATOLOGY + ",");
}
if (getBusinessDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_ECONOMY + ",");
}
if (getElevationDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_ELEVATION + ",");
}
if (getEnvironmentDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_ENVIRONMENT + ",");
}
if (getGeologicalDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_GEOSCIENTIFIC + ",");
}
if (getHumanDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_HEALTH + ",");
}
if (getImageryDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_IMAGERY + ",");
}
if (getMilitaryDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_MILITARY + ",");
}
if (getInlandWaterDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_INLAND_WATERS + ",");
}
if (getLocationsDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_LOCATION + ",");
}
if (getOceansDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_OCEANS + ",");
}
if (getCadastralDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_CADASTRAL + ",");
}
if (getCulturalDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_SOCIETY + ",");
}
if (getFacilitiesDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_STRUCTURE + ",");
}
if (getTransportationDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_TRANSPORTATION + ",");
}
if (getUtilitiesDC()) {
cats += (CswSearchCriteria.TOPIC_CAT_UTILITIES + ",");
}
if (cats.length() > 0) {
// remove the last ','
cats = cats.substring(0, cats.length() - 1);
props.put("topicCategories", cats);
}
}
}
records = catalog.lookup(props);
if (records.size() <= 0) {
renderMessage(TextResources.getResourceString(
"csw.ui.label.noResultsFound"));
}
wResults = event.getWebContext().getWebResults();
rootNode = new ResultNode("Search Results: " + catalog.getName());
actions = new LinkedHashMap<String, String>();
for (IMetadataDocument doc : records) {
Map<String, String> detailMap = null;
ICswSearchResult cswResult = null;
try {
cswResult = (CswSearchResult) Class.forName(m_searchResultClass)
.newInstance();
cswResult.setWebContext(event.getWebContext());
cswResult.setMetadataCatalog(catalog);
cswResult.setMetadataDocument(doc);
cswResult.setActionHandlers(m_actionHandlers);
WebPolygon geom = null;
WebRing ring = null;
WebPoint point = null;
if (!doc.getMetadataProfile().getExporters()
.containsKey("basicMetadataExporter")) {
_logger.warn(
"Unable to get display fields for CS/W record - skipping.");
_logger.debug(
"BasicMetadataExporter is missing or not configured properly.");
continue;
} else if (!(doc.getMetadataProfile().getExporters()
.get("basicMetadataExporter") instanceof BasicMetadataExporter)) {
_logger.warn(
"Unable to get display fields for CS/W record - skipping.");
_logger.debug(
"Basic metadata exporter is not an instanceof BasicMetadataExporter.");
continue;
}
basicExporter = (BasicMetadataExporter) doc.getMetadataProfile()
.getExporters()
.get("basicMetadataExporter");
if (basicExporter == null) {
_logger.warn(
"Unable to get display fields for CS/W record - skipping.");
continue;
}
doc.export(basicExporter);
detailMap = buildResultDetails(basicExporter);
for (IActionHandler ah : m_actionHandlers) {
if (ah.shouldDisplay(basicExporter)) {
actions.put(ah.getActionKey(), "executeAction");
}
}
cswResult.setDisplayName(basicExporter.getTitle());
cswResult.setLiveDataOrMap(basicExporter.isLiveDataOrMap());
cswResult.setDetails(detailMap);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -