From: Niels Erik G. Nielsen Date: Tue, 21 May 2013 15:17:40 +0000 (-0400) Subject: Organizes SP specific responses in separate class X-Git-Tag: v0.0.7~91 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=67c31a7381c986cb0473f2cc18cd0ade946a7e4e;p=mkjsf-moved-to-github.git Organizes SP specific responses in separate class Also: introduces reset-levels: all from search and beyond all fron init and beyond all from auth and beyond for clarity when switching service URL's and service IDs --- diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java index 29d9280..1a1b1f9 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java @@ -26,7 +26,6 @@ import com.indexdata.mkjsf.errors.ErrorHelper; import com.indexdata.mkjsf.pazpar2.commands.CommandParameter; import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command; import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Commands; -import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; import com.indexdata.mkjsf.pazpar2.data.RecordResponse; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; import com.indexdata.mkjsf.pazpar2.data.ResponseParser; @@ -98,7 +97,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria errors.addConfigurationError(new ConfigurationError("Search Client","Configuration",e.getMessage())); } logger.info(configReader.document()); - pzresp.resetAllSessionData(); + pzresp.getSp().resetAuthAndBeyond(true); } public void resetSearchAndRecordCommands () { @@ -119,9 +118,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria errors.addConfigurationError(new ConfigurationError("No client defined","Client is null","No search client defined. A client must be pre-configured or selected runtime, prior to searching.")); } else { stateMgr.hasPendingStateChange("search",false); - pzresp.resetSearchResponses(); - // resets some record and show command parameters without - // changing state or creating state change feedback + pzresp.resetSearchAndBeyond(); pzreq.getRecord().removeParametersInState(); pzreq.getShow().setParameterInState(new CommandParameter("start","=",0)); logger.debug(Utils.objectId(this) + " is searching using "+pzreq.getCommand("search").getUrlEncodedParameterValue("query")); @@ -405,7 +402,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria if (url!=null && searchClient != null && !url.equals(searchClient.getServiceUrl())) { pzreq.getRecord().removeParametersInState(); pzreq.getSearch().removeParametersInState(); - pzresp.resetAllSessionData(); + pzresp.getSp().resetAuthAndBeyond(true); user.clear(); searchClient.setServiceUrl(url); } @@ -418,7 +415,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria public void setServiceId () { pzreq.getRecord().removeParametersInState(); pzreq.getSearch().removeParametersInState(); - pzresp.resetSearchResponses(); + pzresp.resetSearchAndBeyond(); pz2Client.setServiceId(pzreq.getInit().getService()); } @@ -542,7 +539,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria if (!serviceType.equals(type) && !serviceType.equals(SERVICE_TYPE_TBD)) { resetSearchAndRecordCommands(); - pzresp.resetAllSessionData(); + pzresp.getSp().resetAuthAndBeyond(true); } serviceType = type; if (serviceType.equals(SERVICE_TYPE_PZ2)) { diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java index 3b33000..9d4ee91 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java @@ -9,9 +9,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.faces.context.ExternalContext; -import javax.faces.context.FacesContext; - import org.apache.log4j.Logger; import com.indexdata.masterkey.config.MissingMandatoryParameterException; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java index 3c0da10..ff69dcc 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java @@ -64,7 +64,7 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab public String login(String navigateTo) { logger.info("doing login by " + user + " using " + pz2 + " and client " + pz2.getSpClient()); pz2.resetSearchAndRecordCommands(); - pzresp.resetAllSessionData(); + pzresp.getSp().resetAuthAndBeyond(true); AuthCommand auth = pzreq.getSp().getAuth(); auth.setParametersInState(new CommandParameter("action","=","login"), new CommandParameter("username","=",user.getName()), @@ -93,7 +93,7 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab user.clear(); } pz2.resetSearchAndRecordCommands(); - pzresp.resetAllSessionData(); + pzresp.getSp().resetAuthAndBeyond(true); AuthCommand auth = pzreq.getSp().getAuth(); auth.setParameterInState(new CommandParameter("action","=","ipAuth")); ClientCommandResponse commandResponse = pz2.getSpClient().send(auth); @@ -138,9 +138,9 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab public ClientCommandResponse postInit() throws UnsupportedEncodingException, IOException { String initDocPath = pz2.getSpClient().getInitDocPaths().get(0); logger.info("Paths: " + pz2.getSpClient().getInitDocPaths()); - logger.info("Path: " + initDocPath); + logger.info("Path: " + initDocPath); pz2.resetSearchAndRecordCommands(); - pzresp.resetAllSessionData(); + pzresp.getSp().resetAuthAndBeyond(true); ClientCommandResponse response = pz2.getSpClient().postInitDoc(initDocPath + getInitFileName()); return response; } @@ -148,7 +148,7 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab @Override public HttpResponseWrapper postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException { pz2.resetSearchAndRecordCommands(); - pzresp.resetAllSessionData(); + pzresp.getSp().resetAuthAndBeyond(true); HttpResponseWrapper response = pz2.getSpClient().postInitDoc(initDoc,includeDebug); return response; } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java index 1df2363..e076644 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java @@ -16,8 +16,7 @@ import org.apache.log4j.Logger; import com.indexdata.mkjsf.errors.ErrorHelper; import com.indexdata.mkjsf.errors.ErrorInterface; -import com.indexdata.mkjsf.pazpar2.data.sp.AuthResponse; -import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse; +import com.indexdata.mkjsf.pazpar2.data.sp.SpResponses; import com.indexdata.mkjsf.utils.Utils; @Named("pzresp") @SessionScoped @@ -27,6 +26,7 @@ public class Responses implements Serializable { protected Map dataObjects = new ConcurrentHashMap(); private static Logger logger = Logger.getLogger(Responses.class); private ErrorHelper errorHelper = null; + private SpResponses sp = null; public Responses() { } @@ -75,25 +75,23 @@ public class Responses implements Serializable { return error; } - public void resetSearchResponses() { + public void resetSearchAndBeyond() { logger.debug("Resetting show,stat,termlist,bytarget,record,search response objects."); dataObjects.put("show", new ShowResponse()); dataObjects.put("stat", new StatResponse()); dataObjects.put("termlist", new TermListsResponse()); dataObjects.put("bytarget", new ByTarget()); dataObjects.put("record", new RecordResponse()); - dataObjects.put("search", new SearchResponse()); + dataObjects.put("search", new SearchResponse()); + getSp().resetSearchAndBeyond(false); } - public void resetAllSessionData () { - logger.debug("Resetting all response objects"); - dataObjects = new ConcurrentHashMap(); - resetSearchResponses(); - dataObjects.put("init", new InitResponse()); - dataObjects.put("auth", new AuthResponse()); - dataObjects.put("categories", new CategoriesResponse()); + public void resetInitAndBeyond () { + dataObjects.put("init", new InitResponse()); + resetSearchAndBeyond(); + getSp().resetInitAndBeyond(false); } - + public InitResponse getInit () { return ((InitResponse) dataObjects.get("init")); } @@ -130,17 +128,6 @@ public class Responses implements Serializable { return ((ByTarget) dataObjects.get("bytarget")); } - // Service Proxy extras - public AuthResponse getAuth () { - return ((AuthResponse) dataObjects.get("auth")); - } - - public CategoriesResponse getCategories() { - return ((CategoriesResponse) dataObjects.get("categories")); - } - // Service Proxy extras - - public ResponseDataObject getResponseObject (String name) { return dataObjects.get(name); } @@ -182,4 +169,8 @@ public class Responses implements Serializable { facesContext.responseComplete(); } + public SpResponses getSp() { + return (sp == null ? new SpResponses(this) : sp); + } + } \ No newline at end of file diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/SpResponses.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/SpResponses.java index db58ca9..b5bb18c 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/SpResponses.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/SpResponses.java @@ -1,9 +1,64 @@ package com.indexdata.mkjsf.pazpar2.data.sp; -public class SpResponses { +import java.io.Serializable; - public SpResponses() { - // TODO Auto-generated constructor stub +import com.indexdata.mkjsf.pazpar2.data.Responses; + +public class SpResponses implements Serializable { + + private static final long serialVersionUID = -3831357590639961167L; + private Responses responses = null; + + public SpResponses(Responses responses) { + this.responses = responses; + } + + /** + * Resets all responses from the search request to any request + * that can follow search (i.e. show and bytarget but not init or auth) + * @param includePazpar2Responses Set to true if the invocation should + * reset Pazpar2 responses + * (non-SP-specific responses) as well. + */ + public void resetSearchAndBeyond(boolean includePazpar2Responses) { + if (includePazpar2Responses) { + responses.resetSearchAndBeyond(); + } + } + + /** + * Resets all responses from the init request to any request + * that can follow init (i.e. search and show but not auth) + * @param includePazpar2Responses Set to true if the invocation should + * reset Pazpar2 responses + * (non-SP-specific responses) as well. + */ + public void resetInitAndBeyond (boolean includePazpar2Responses) { + responses.put("categories", new CategoriesResponse()); + if (includePazpar2Responses) { + responses.resetInitAndBeyond(); + } + resetSearchAndBeyond(includePazpar2Responses); + } + + /** + * Resets all responses from the authentication request to any request + * that can follow authentication. + * @param includePazpar2Responses Set to true if the invocation should + * reset Pazpar2 responses + * (non-SP-specific responses) as well. + */ + public void resetAuthAndBeyond (boolean includePazpar2Responses) { + responses.put("auth", new AuthResponse()); + resetInitAndBeyond(includePazpar2Responses); + } + + public AuthResponse getAuth () { + return ((AuthResponse) responses.getResponseObject("auth")); + } + + public CategoriesResponse getCategories() { + return ((CategoriesResponse) responses.getResponseObject("categories")); } }