Skip to content

Commit

Permalink
need CatalogSearcher to clear old selection on new searches
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Eichar committed Sep 25, 2012
1 parent 996c80b commit 12c3a53
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
@@ -0,0 +1,48 @@
package org.fao.geonet.kernel.csw.services.getrecords;

import org.fao.geonet.util.Sha1Encoder;
import org.jdom.Element;

import jeeves.server.context.ServiceContext;
import jeeves.utils.Xml;

public class QueryReprentationForSession {

private final String language;
private final String query;
private final String userid;

public QueryReprentationForSession( ServiceContext context, Element filterExpr ) {
this.language = context.getLanguage();
this.query = Sha1Encoder.encodeString (Xml.getString(filterExpr));
this.userid = context.getUserSession().getUserId();
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((language == null) ? 0 : language.hashCode());
result = prime * result + ((query == null) ? 0 : query.hashCode());
result = prime * result + ((userid == null) ? 0 : userid.hashCode());
return result;
}

@Override
public boolean equals( Object obj ) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
QueryReprentationForSession other = (QueryReprentationForSession) obj;
if (language == null) {
if (other.language != null) return false;
} else if (!language.equals(other.language)) return false;
if (query == null) {
if (other.query != null) return false;
} else if (!query.equals(other.query)) return false;
if (userid == null) {
if (other.userid != null) return false;
} else if (!userid.equals(other.userid)) return false;
return true;
}
}
Expand Up @@ -164,6 +164,9 @@ public Pair<Element, Element> search(ServiceContext context, int startPos, int m
Pair<Element, List<ResultItem>> summaryAndSearchResults = searcher .search(context, filterExpr, filterVersion,
typeName, sort, resultType, startPos, maxRecords, maxHitsFromSummary, cswServiceSpecificContraint);

// store search results in user session
storeInUserSession(searcher, context, filterExpr);

// retrieve actual metadata for results
int counter = retrieveMetadataMatchingResults(context, results, summaryAndSearchResults, maxRecords, setName,
outSchema, elemNames, typeName, resultType, strategy);
Expand Down Expand Up @@ -232,6 +235,37 @@ private int retrieveMetadataMatchingResults(ServiceContext context,
}
return counter;
}
/**
* Stores searcher (with results) in user session.
* @param searcher
*
* @param context service context
* @param filterExpr FilterExpression
*/
private void storeInUserSession(CatalogSearcher searcher, ServiceContext context, Element filterExpr) {
//
// keep results in user session
//
UserSession session = context.getUserSession();
session.setProperty(Geonet.Session.SEARCH_RESULT, searcher);
//
// clear selection from session when query filter change
//
QueryReprentationForSession sessionQueryReprentation = (QueryReprentationForSession) session.getProperty(Geonet.Session.SEARCH_REQUEST_ID);
QueryReprentationForSession requestQueryReprentation = new QueryReprentationForSession(context, filterExpr);

if (sessionQueryReprentation == null ||
!requestQueryReprentation.equals(sessionQueryReprentation)) {
// possibly close old selection
SelectionManager oldSelection = (SelectionManager)session.getProperty(Geonet.Session.SELECTED_RESULT);
if (oldSelection != null){
oldSelection.close();
oldSelection = null;
}
}
session.setProperty(Geonet.Session.SEARCH_REQUEST_ID, requestQueryReprentation);
}

/**
* Retrieves metadata from the database. Conversion between metadata record and output schema are defined in
* xml/csw/schemas/ directory.
Expand Down

0 comments on commit 12c3a53

Please sign in to comment.