From 86f289cd42ba95846c80d22129ed565e4e9d6dde Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Thu, 6 Jun 2013 15:56:05 -0400 Subject: [PATCH] Renames class, removes obsolete, javadoc --- .../com/indexdata/mkjsf/config/package-info.java | 4 +- .../mkjsf/pazpar2/ClientCommandResponse.java | 43 ++++++++++++++++++ .../com/indexdata/mkjsf/pazpar2/CommandThread.java | 7 +++ .../com/indexdata/mkjsf/pazpar2/Pz2Client.java | 48 +++++++++++++++++++- .../com/indexdata/mkjsf/pazpar2/Pz2Service.java | 33 +++++++++++++- .../mkjsf/pazpar2/ServiceProxyClient.java | 21 +++++++++ .../mkjsf/pazpar2/commands/BytargetCommand.java | 2 +- .../mkjsf/pazpar2/commands/InitCommand.java | 2 +- .../mkjsf/pazpar2/commands/PingCommand.java | 2 +- .../mkjsf/pazpar2/commands/RecordCommand.java | 10 +++- .../mkjsf/pazpar2/commands/SearchCommand.java | 2 +- .../mkjsf/pazpar2/commands/SettingsCommand.java | 2 +- .../mkjsf/pazpar2/commands/ShowCommand.java | 2 +- .../mkjsf/pazpar2/commands/StatCommand.java | 2 +- .../mkjsf/pazpar2/commands/TermlistCommand.java | 2 +- .../mkjsf/pazpar2/commands/sp/AuthCommand.java | 2 +- .../pazpar2/commands/sp/CategoriesCommand.java | 2 +- .../mkjsf/pazpar2/commands/sp/RecordCommandSp.java | 3 +- .../com/indexdata/mkjsf/pazpar2/data/ByTarget.java | 22 --------- .../mkjsf/pazpar2/data/ByTargetResponse.java | 28 ++++++++++++ .../java/com/indexdata/mkjsf/pazpar2/data/Hit.java | 6 +++ .../indexdata/mkjsf/pazpar2/data/InitResponse.java | 6 +++ .../com/indexdata/mkjsf/pazpar2/data/Location.java | 7 ++- .../mkjsf/pazpar2/data/RecordOffsetResponse.java | 8 ---- .../mkjsf/pazpar2/data/RecordResponse.java | 6 +++ .../mkjsf/pazpar2/data/ResponseDataObject.java | 18 ++++++++ .../mkjsf/pazpar2/data/ResponseParser.java | 8 +++- .../indexdata/mkjsf/pazpar2/data/Responses.java | 20 ++++++-- .../mkjsf/pazpar2/data/SearchResponse.java | 6 +++ .../indexdata/mkjsf/pazpar2/data/ShowResponse.java | 6 +++ .../indexdata/mkjsf/pazpar2/data/StatResponse.java | 6 +++ .../com/indexdata/mkjsf/pazpar2/data/Target.java | 6 +++ .../mkjsf/pazpar2/data/TermListResponse.java | 7 ++- .../mkjsf/pazpar2/data/TermListsResponse.java | 6 +++ .../indexdata/mkjsf/pazpar2/data/TermResponse.java | 6 +++ .../mkjsf/pazpar2/data/TermXTargetResponse.java | 16 +++++-- .../indexdata/mkjsf/pazpar2/data/package-info.java | 18 ++++++++ .../mkjsf/pazpar2/data/sp/AuthResponse.java | 6 +++ .../mkjsf/pazpar2/data/sp/CategoriesResponse.java | 6 +++ .../mkjsf/pazpar2/data/sp/TargetCategory.java | 6 +++ .../com/indexdata/mkjsf/pazpar2/package-info.java | 6 +-- 41 files changed, 359 insertions(+), 60 deletions(-) delete mode 100644 src/main/java/com/indexdata/mkjsf/pazpar2/data/ByTarget.java create mode 100644 src/main/java/com/indexdata/mkjsf/pazpar2/data/ByTargetResponse.java delete mode 100644 src/main/java/com/indexdata/mkjsf/pazpar2/data/RecordOffsetResponse.java create mode 100644 src/main/java/com/indexdata/mkjsf/pazpar2/data/package-info.java diff --git a/src/main/java/com/indexdata/mkjsf/config/package-info.java b/src/main/java/com/indexdata/mkjsf/config/package-info.java index a131afc..6716e66 100644 --- a/src/main/java/com/indexdata/mkjsf/config/package-info.java +++ b/src/main/java/com/indexdata/mkjsf/config/package-info.java @@ -77,7 +77,7 @@ * * pz2client.PAZPAR2_URL = http://localhost:8004/ * - *

Some of the other know parameters in this format could be:

+ *

Some of the other known parameters in this format could be:

* *
  * service.TYPE = SP              
@@ -89,7 +89,7 @@
  * and inject that class in beans.xml instead of any of the two predefined options. The extended
  * class must construct a Configuration object -- which is basically a set of key-value pairs -- 
  * and then set the desired values and hand it off to the Configurable (currently Pz2Service, Pz2Client, 
- * ServiceProxyClient

+ * and ServiceProxyClient)

* *

Finally it's possible to set the URL runtime even from the UI pages.

* diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ClientCommandResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ClientCommandResponse.java index 01444ef..ef22114 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/ClientCommandResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/ClientCommandResponse.java @@ -5,6 +5,15 @@ import java.io.UnsupportedEncodingException; import com.indexdata.masterkey.pazpar2.client.Pazpar2HttpResponse; +/** + * Contains one HTTP response to a command executed against a Pazpar2 service in such a + * way as to give the response parser a common interface to responses, whether + * they are from Pazpar2, from the Service Proxy, or are error messages created + * by the JSF application during processing. + * + * @author Niels Erik + * + */ public class ClientCommandResponse implements HttpResponseWrapper { private int statusCode; @@ -13,18 +22,38 @@ public class ClientCommandResponse implements HttpResponseWrapper { private String contentString = null; private byte[] bytesForParsing = null; + /** + * Used for storing Pazpar2 based response + * + * @param pz2response + * @param content + */ public ClientCommandResponse(Pazpar2HttpResponse pz2response, ByteArrayOutputStream content) { this.content = content.toByteArray(); this.statusCode = pz2response.getStatusCode(); this.contentType = pz2response.getContentType(); } + /** + * Used for storing error response + * + * @param statusCode + * @param content + * @param contentType + */ public ClientCommandResponse(int statusCode, String content, String contentType) { this.statusCode = statusCode; this.contentString = content; this.contentType = contentType; } + /** + * Used for storing Service Proxy based response + * + * @param statusCode + * @param content + * @param contentType + */ public ClientCommandResponse(int statusCode, byte[] content, String contentType) { this.statusCode = statusCode; this.content = content; @@ -41,6 +70,9 @@ public class ClientCommandResponse implements HttpResponseWrapper { return contentType; } + /** + * Gets the response as a String - unless the response is marked as binary + */ @Override public String getResponseString() { if (content == null) { @@ -62,6 +94,13 @@ public class ClientCommandResponse implements HttpResponseWrapper { return content; } + /** + * Overrides the original response with a modified response. Used for + * one instance of a response that is not named by the command that + * created it - such as the parser expects. + * + * @param parseString + */ public void setResponseToParse(String parseString) { try { this.bytesForParsing = parseString.getBytes("UTF-8"); @@ -70,6 +109,10 @@ public class ClientCommandResponse implements HttpResponseWrapper { } } + /** + * Used by the parser to get the response for further processing. + * @return + */ public byte[] getResponseToParse() { if (bytesForParsing != null) { return bytesForParsing; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/CommandThread.java b/src/main/java/com/indexdata/mkjsf/pazpar2/CommandThread.java index 7ebdf9f..678e4a6 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/CommandThread.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/CommandThread.java @@ -5,6 +5,13 @@ import org.apache.log4j.Logger; import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command; import com.indexdata.mkjsf.pazpar2.data.Responses; +/** + * Helper class for running multiple concurrent Pazpar2 commands. Basically + * used for updating display data (show,stat,bytarget,termlist) together. + * + * @author Niels Erik + * + */ public class CommandThread extends Thread { private static Logger logger = Logger.getLogger(CommandThread.class); diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java index 6dfe77f..3417a47 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java @@ -27,6 +27,20 @@ import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command; import com.indexdata.mkjsf.pazpar2.data.CommandError; import com.indexdata.mkjsf.utils.Utils; +/** + * Search client handling straight Pazpar2 requests. + * + *

Although it is described here as straight Pazpar2, the client itself + * actually represents a layer between Pazpar2 and the JSF application because it + * uses the Pazpar2 client from the library masterkey-common.

+ * That client, which is the one also used by the Service Proxy, does perform certain + * types of session handling, bootstraps lost sessions, avoids repeating already + * executed queries etc, so it is -- in other words -- still a mediated interaction + * with Pazpar2 that takes place. At least for now.

+ * + * @author Niels Erik + * + */ public class Pz2Client implements SearchClient { private static final long serialVersionUID = 5414266730169982028L; @@ -88,6 +102,13 @@ public class Pz2Client implements SearchClient { client.setSearchCommand(clientCommand); } + /** + * Runs the give Pazpar2 command and returns a response wrapper with either the received response or + * with some form of error message. + * + * It is intended that this method never throws an exception. All events are supposed to be captured and + * returned in some form of response. + */ @Override public HttpResponseWrapper executeCommand(Pazpar2Command command) { ClientCommandResponse commandResponse = null; @@ -132,7 +153,7 @@ public class Pz2Client implements SearchClient { commandResponse = new ClientCommandResponse(0,CommandError.createErrorXml(command.getCommandName(), "", "ServiceError", e.getMessage(),""),"text/xml"); } long end = System.currentTimeMillis(); - logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." ); + logger.info("Executed " + command.getCommandName() + " in " + (end-start) + " ms." ); return commandResponse; } @@ -144,11 +165,17 @@ public class Pz2Client implements SearchClient { return clone; } + /** + * Returns default configuration parameters for the client. + */ @Override public Map getDefaults() { return DEFAULTS; } + /** + * Returns the configuration name of the client + */ @Override public String getModuleName() { return MODULENAME; @@ -178,6 +205,9 @@ public class Pz2Client implements SearchClient { } } + /** + * Provides configuration documentation -- mostly for diagnosing problems + */ @Override public List documentConfiguration() { List doc = new ArrayList(); @@ -189,25 +219,41 @@ public class Pz2Client implements SearchClient { return config; } + /** + * Returns the currently configured Papzar2 URL. + */ @Override public String getServiceUrl() { return cfg.PAZPAR2_URL; } + /** + * Returns true if a Papzar2 URL was defined yet. + */ @Override public boolean hasServiceUrl() { return cfg.PAZPAR2_URL != null && cfg.PAZPAR2_URL.length()>0; } + /** + * Sets the Pazpar2 URL to use for requests. + */ @Override public void setServiceUrl (String serviceUrl) { cfg.PAZPAR2_URL = serviceUrl; } + /** + * Returns the Pazpar2 Service ID + */ public String getServiceId () { return cfg.PAZPAR2_SERVICE_ID; } + /** + * Sets the service ID that Pazpar2 should use when servicing requests + * @param serviceId + */ public void setServiceId(String serviceId) { cfg.PAZPAR2_SERVICE_ID = serviceId; try { diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Service.java b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Service.java index efbcfe3..4d6d05f 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Service.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Service.java @@ -322,6 +322,9 @@ public class Pz2Service implements StateListener, Configurable, Serializable { } } + /** + * Used by the state manager to notify Pz2Service about state changes + */ @Override public void stateUpdated(String commandName) { logger.debug("State change reported for [" + commandName + "]"); @@ -413,12 +416,21 @@ public class Pz2Service implements StateListener, Configurable, Serializable { return pager; } + /** + * Sets the URL of the Service Proxy to use for requests + * + * @param url + */ public void setServiceProxyUrl(String url) { searchClient = spClient; setServiceType(SERVICE_TYPE_SP); setServiceUrl(url); } + /** + * Returns the Service Proxy URL currently defined for servicing requests + * + */ public String getServiceProxyUrl () { if (isServiceProxyService()) { return spClient.getServiceUrl(); @@ -426,13 +438,22 @@ public class Pz2Service implements StateListener, Configurable, Serializable { return ""; } } - + + /** + * Sets the URL of the Pazpar2 to use for requests + * + * @param url + */ public void setPazpar2Url(String url) { searchClient = pz2Client; setServiceType(SERVICE_TYPE_PZ2); setServiceUrl(url); } + /** + * Returns the Pazpar2 URL currently defined for servicing requests + * + */ public String getPazpar2Url() { if (isPazpar2Service()) { return pz2Client.getServiceUrl(); @@ -441,6 +462,12 @@ public class Pz2Service implements StateListener, Configurable, Serializable { } } + /** + * Sets the URL to be used by the currently selected search client + * when running requests. + * + * @param url + */ public void setServiceUrl(String url) { if (url!=null && searchClient != null && !url.equals(searchClient.getServiceUrl())) { pzreq.getRecord().removeParametersInState(); @@ -450,6 +477,10 @@ public class Pz2Service implements StateListener, Configurable, Serializable { } } + /** + * Gets the currently selected URL used for executing requests. + * @return + */ public String getServiceUrl() { return (searchClient!=null ? searchClient.getServiceUrl() : ""); } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java index 2956afc..ace35b1 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java @@ -41,6 +41,12 @@ import com.indexdata.mkjsf.pazpar2.commands.sp.AuthCommand; import com.indexdata.mkjsf.pazpar2.data.CommandError; import com.indexdata.mkjsf.utils.Utils; +/** + * Search client handling Service Proxy requests. + * + * @author Niels Erik + * + */ public class ServiceProxyClient implements SearchClient { private static final long serialVersionUID = -4031644009579840277L; @@ -165,6 +171,9 @@ public class ServiceProxyClient implements SearchClient { return handler.getReasonPhrase(); } + /** + * Does nothing in Service Proxy context + */ @Override public void setSearchCommand(Pazpar2Command command) { // Do nothing, Service Proxy is handling this @@ -184,11 +193,17 @@ public class ServiceProxyClient implements SearchClient { return clone; } + /** + * Returns default configuration parameters for the client. + */ @Override public Map getDefaults() { return new HashMap(); } + /** + * Returns the configuration name of the client + */ @Override public String getModuleName() { return MODULENAME; @@ -251,6 +266,9 @@ public class ServiceProxyClient implements SearchClient { return commandResponse; } + /** + * Sets the URL of the Service Proxy that should service requests. + */ public void setServiceUrl (String url) { serviceUrl = url; } @@ -264,6 +282,9 @@ public class ServiceProxyClient implements SearchClient { return serviceUrl; } + /** + * Returns true if a Service Proxy URL was defined yet. + */ @Override public boolean hasServiceUrl() { return serviceUrl != null && serviceUrl.length()>0; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/BytargetCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/BytargetCommand.java index 02a2307..786ae4c 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/BytargetCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/BytargetCommand.java @@ -3,7 +3,7 @@ package com.indexdata.mkjsf.pazpar2.commands; import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; /** - * Represents a Pazpar2 bytarget command + * Represents a Pazpar2 bytarget command, can be accessed by pzreq.bytarget * * @author Niels Erik * diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/InitCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/InitCommand.java index e98a5cf..ab2e5a1 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/InitCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/InitCommand.java @@ -6,7 +6,7 @@ import com.indexdata.mkjsf.pazpar2.commands.sp.InitCommandSp; import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; /** - * Represents a Pazpar2 init command. + * Represents a Pazpar2 init command, can be accessed by pzreq.init * * @author Niels Erik * diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/PingCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/PingCommand.java index 6d3d024..a695746 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/PingCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/PingCommand.java @@ -3,7 +3,7 @@ package com.indexdata.mkjsf.pazpar2.commands; import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; /** - * Represents a Pazpar2 ping command. + * Represents a Pazpar2 ping command, , can be accessed by pzreq.init * * @author Niels Erik * diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java index d453b75..8cc039d 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java @@ -12,7 +12,7 @@ import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; import com.indexdata.mkjsf.pazpar2.data.ResponseParser; /** - * Represents a Pazpar2 record command. + * Represents a Pazpar2 record command, can be accessed by pzreq.record * * @author Niels Erik * @@ -27,6 +27,14 @@ public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand super("record"); } + /** + * Special handling of record responses since they come in three distinctly different ways + *
    + *
  1. As a regular <record> document
  2. + *
  3. In arbitrary XML format, in case of an offset request to get the native format
  4. + *
  5. In binary (non XML) format
  6. + *
+ */ @Override public ResponseDataObject run() { ResponseDataObject responseObject = null; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java index 59c1370..f2c53da 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java @@ -13,7 +13,7 @@ import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; /** - * Represents a Pazpar2 search command. + * Represents a Pazpar2 search command, can be accessed by pzreq.search * * @author Niels Erik * diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SettingsCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SettingsCommand.java index e2b8d29..ebef90f 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SettingsCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SettingsCommand.java @@ -3,7 +3,7 @@ package com.indexdata.mkjsf.pazpar2.commands; import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; /** - * Represents a Pazpar2 settings command. + * Represents a Pazpar2 settings command, can be accessed by pzreq.settings * * @author Niels Erik * diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/ShowCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/ShowCommand.java index a24172a..04a87d8 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/ShowCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/ShowCommand.java @@ -4,7 +4,7 @@ import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; /** - * Represents a Pazpar2 show command. + * Represents a Pazpar2 show command, can be accessed by pzreq.show * * @author Niels Erik * diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/StatCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/StatCommand.java index b415ec4..5229060 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/StatCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/StatCommand.java @@ -3,7 +3,7 @@ package com.indexdata.mkjsf.pazpar2.commands; import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; /** - * Represents a Pazpar2 stat command. + * Represents a Pazpar2 stat command, can be accessed by pzreq.state * * @author Niels Erik * diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/TermlistCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/TermlistCommand.java index adb84a3..6f3c662 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/TermlistCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/TermlistCommand.java @@ -3,7 +3,7 @@ package com.indexdata.mkjsf.pazpar2.commands; import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; /** - * Represents a Pazpar2 termlist command. + * Represents a Pazpar2 termlist command, can be accessed by pzreq.termlist * * @author Niels Erik * diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/AuthCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/AuthCommand.java index 67780e5..75d46aa 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/AuthCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/AuthCommand.java @@ -10,7 +10,7 @@ import com.indexdata.mkjsf.pazpar2.data.ResponseParser; import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject; /** - * Represents a Service Proxy auth command. + * Represents a Service Proxy auth command, can be accessed by pzreq.sp.auth * *

Authenticates a user against a Pazpar2 Service Proxy

* diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/CategoriesCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/CategoriesCommand.java index 756f85c..e94ce26 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/CategoriesCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/CategoriesCommand.java @@ -7,7 +7,7 @@ import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command; import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse; /** - * Represents a Service Proxy categories command. + * Represents a Service Proxy categories command, can be accessed by pzreq.sp.categories * *

Retrieves target categories available to the current Service Proxy user.

*

Target categories can be used to limit a search to resources tagged with the given diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/RecordCommandSp.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/RecordCommandSp.java index e1b94d8..0b40381 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/RecordCommandSp.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/RecordCommandSp.java @@ -6,7 +6,8 @@ import com.indexdata.mkjsf.pazpar2.commands.CommandParameter; import com.indexdata.mkjsf.pazpar2.commands.RecordCommand; /** - * Service Proxy extensions to the Papzar2 record command. + * Service Proxy extensions to the Papzar2 record command, + * these parameters being accessible by pzreq.record.sp.[parameter] * * @author Niels Erik * diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ByTarget.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ByTarget.java deleted file mode 100644 index b98bf1a..0000000 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ByTarget.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.indexdata.mkjsf.pazpar2.data; - -import java.util.ArrayList; -import java.util.List; - -import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; -import com.indexdata.mkjsf.pazpar2.data.Target; - -public class ByTarget extends ResponseDataObject { - - private static final long serialVersionUID = 3960644950805644518L; - - public List getTargets() { - List targets = new ArrayList(); - if (getElements("target") != null) { - for (ResponseDataObject element : getElements("target")) { - targets.add((Target)element); - } - } - return targets; - } -} diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ByTargetResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ByTargetResponse.java new file mode 100644 index 0000000..f69f21b --- /dev/null +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ByTargetResponse.java @@ -0,0 +1,28 @@ +package com.indexdata.mkjsf.pazpar2.data; + +import java.util.ArrayList; +import java.util.List; + +import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; +import com.indexdata.mkjsf.pazpar2.data.Target; + +/** + * Data from the bytarget command, can be accessed by pzresp.byTarget + * + * @author Niels Erik + * + */ +public class ByTargetResponse extends ResponseDataObject { + + private static final long serialVersionUID = 3960644950805644518L; + + public List getTargets() { + List targets = new ArrayList(); + if (getElements("target") != null) { + for (ResponseDataObject element : getElements("target")) { + targets.add((Target)element); + } + } + return targets; + } +} diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Hit.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Hit.java index 7b6885a..a50dbc8 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Hit.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Hit.java @@ -6,6 +6,12 @@ import java.util.List; import com.indexdata.mkjsf.pazpar2.data.Location; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; +/** + * Data from the show command, child object of ShowResponse, can be accessed by pzresp.show.hits + * + * @author Niels Erik + * + */ public class Hit extends ResponseDataObject { diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/InitResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/InitResponse.java index 76eda96..370e949 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/InitResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/InitResponse.java @@ -1,5 +1,11 @@ package com.indexdata.mkjsf.pazpar2.data; +/** + * Data from the init command, can be accessed by pzresp.init + * + * @author Niels Erik + * + */ public class InitResponse extends ResponseDataObject { private static final long serialVersionUID = -1479775157276901600L; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Location.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Location.java index 19b1dcf..8cbfb90 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Location.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Location.java @@ -2,7 +2,12 @@ package com.indexdata.mkjsf.pazpar2.data; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; - +/** + * Data from the show command, child object of Hit + * + * @author Niels Erik + * + */ public class Location extends ResponseDataObject { private static final long serialVersionUID = -1386527442857478225L; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/RecordOffsetResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/RecordOffsetResponse.java deleted file mode 100644 index d8920b0..0000000 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/RecordOffsetResponse.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.indexdata.mkjsf.pazpar2.data; - -public class RecordOffsetResponse extends ResponseDataObject { - - private static final long serialVersionUID = -601620728296476450L; - - -} diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/RecordResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/RecordResponse.java index b1de2da..85fdc9a 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/RecordResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/RecordResponse.java @@ -6,6 +6,12 @@ import java.util.List; import com.indexdata.mkjsf.pazpar2.data.Location; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; +/** + * Data from the record command, can be accessed by pzresp.record + * + * @author Niels Erik + * + */ public class RecordResponse extends ResponseDataObject { private static final long serialVersionUID = 6682722004285796002L; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseDataObject.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseDataObject.java index 535f859..5e2d639 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseDataObject.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseDataObject.java @@ -9,6 +9,12 @@ import org.apache.log4j.Logger; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; +/** + * Parent class of all response data objects, with generic methods for retrieving data elements + * + * @author Niels Erik + * + */ public class ResponseDataObject implements Serializable { Logger logger = Logger.getLogger(ResponseDataObject.class); @@ -38,6 +44,12 @@ public class ResponseDataObject implements Serializable { return attributes.get(name); } + /** + * Used by the response XML parser to add child element objects to a parent element object + * + * @param name of the child element + * @param value the child object itself + */ public void addElement (String name, ResponseDataObject value) { if (elements.containsKey(name)) { elements.get(name).add(value); @@ -74,6 +86,12 @@ public class ResponseDataObject implements Serializable { } } + /** + * Returns string array with the values of the named element(s) + * + * @param name of the child object(s) to retrieve value(s) from + * @return + */ public String[] getValueArray (String name) { List elements = getElements(name); String[] valueArray = {}; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseParser.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseParser.java index 179424d..56e4218 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseParser.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseParser.java @@ -23,6 +23,12 @@ import com.indexdata.mkjsf.pazpar2.data.sp.AuthResponse; import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse; import com.indexdata.mkjsf.pazpar2.data.sp.TargetCategory; +/** + * Parses the XML stored in ClientCommandResponses and builds ResponseDataObjects from it. + * + * @author Niels Erik + * + */ public class ResponseParser extends DefaultHandler { private XMLReader xmlReader = null; @@ -99,7 +105,7 @@ public class ResponseParser extends DefaultHandler { } else if (localName.equals("record")) { currentElement = new RecordResponse(); } else if (localName.equals("bytarget")) { - currentElement = new ByTarget(); + currentElement = new ByTargetResponse(); } else if (localName.equals("target")) { currentElement = new Target(); } else if (localName.equals("stat")) { 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 1397023..90e7f8d 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java @@ -20,6 +20,12 @@ import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject; import com.indexdata.mkjsf.pazpar2.data.sp.SpResponses; import com.indexdata.mkjsf.utils.Utils; +/** + * Provides references to all current data objects and has general methods for clearing certain response data. + * + * @author Niels Erik + * + */ @SessionScoped @Named public class Responses implements Serializable { @@ -81,17 +87,25 @@ public class Responses implements Serializable { return error; } + /** + * Empties all data objects populated after a search (including the search response itself) + * + */ 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("bytarget", new ByTargetResponse()); dataObjects.put("record", new RecordResponse()); dataObjects.put("search", new SearchResponse()); getSp().resetSearchAndBeyond(false); } + /** + * Empties all data objects populated after a service was initialized, including the init response itself + * but excluding a possible auth response + */ public void resetInitAndBeyond () { dataObjects.put("init", new InitResponse()); resetSearchAndBeyond(); @@ -130,8 +144,8 @@ public class Responses implements Serializable { return (getTermLists().getTermList(facet).getTerms()); } - public ByTarget getByTarget() { - return ((ByTarget) dataObjects.get("bytarget")); + public ByTargetResponse getByTarget() { + return ((ByTargetResponse) dataObjects.get("bytarget")); } public ResponseDataObject getResponseObject (String name) { diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/SearchResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/SearchResponse.java index 76a41b1..261c08a 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/SearchResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/SearchResponse.java @@ -1,5 +1,11 @@ package com.indexdata.mkjsf.pazpar2.data; +/** + * Data from the search command (a status message), can be accessed by pzresp.search + * + * @author Niels Erik + * + */ public class SearchResponse extends ResponseDataObject { private static final long serialVersionUID = -3320013021497018972L; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ShowResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ShowResponse.java index c845c3a..a8d10c8 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ShowResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ShowResponse.java @@ -6,6 +6,12 @@ import java.util.List; import com.indexdata.mkjsf.pazpar2.data.Hit; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; +/** + * Data from the show command, can be accessed by pzresp.show + * + * @author Niels Erik + * + */ public class ShowResponse extends ResponseDataObject { private static final long serialVersionUID = 7103554232106330370L; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/StatResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/StatResponse.java index b5acf0f..4f44f77 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/StatResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/StatResponse.java @@ -2,6 +2,12 @@ package com.indexdata.mkjsf.pazpar2.data; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; +/** + * Data from the stat command, can be accessed by pzresp.stat + * + * @author Niels Erik + * + */ public class StatResponse extends ResponseDataObject { private static final long serialVersionUID = -6578979787689458761L; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Target.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Target.java index 8942662..b82f74b 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Target.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Target.java @@ -2,6 +2,12 @@ package com.indexdata.mkjsf.pazpar2.data; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; +/** + * Data from the bytarget command, child object of ByTargetResponse + * + * @author Niels Erik + * + */ public class Target extends ResponseDataObject { private static final long serialVersionUID = 3343881183545520108L; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermListResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermListResponse.java index b4c4fb3..d1755c7 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermListResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermListResponse.java @@ -8,7 +8,12 @@ import org.apache.log4j.Logger; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; import com.indexdata.mkjsf.pazpar2.data.TermListResponse; import com.indexdata.mkjsf.pazpar2.data.TermResponse; - +/** + * Data from the termlist command, child object of TermListsResponse + * + * @author Niels Erik + * + */ public class TermListResponse extends ResponseDataObject { private static Logger logger = Logger.getLogger(TermListResponse.class); diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermListsResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermListsResponse.java index 8558e32..dd0ffa6 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermListsResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermListsResponse.java @@ -6,6 +6,12 @@ import java.util.Map; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; import com.indexdata.mkjsf.pazpar2.data.TermListResponse; +/** + * Data from the termlist command, can be accessed by pzresp.termLists + * + * @author Niels Erik + * + */ public class TermListsResponse extends ResponseDataObject { private static final long serialVersionUID = -1370643625715834978L; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermResponse.java index 9c3ddb1..3a0c2d8 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermResponse.java @@ -2,6 +2,12 @@ package com.indexdata.mkjsf.pazpar2.data; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; +/** + * Data from the termlist command, child object of TermListResponse + * + * @author Niels Erik + * + */ public class TermResponse extends ResponseDataObject { private static final long serialVersionUID = -8323959763575180678L; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermXTargetResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermXTargetResponse.java index c244516..a7e6f36 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermXTargetResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/TermXTargetResponse.java @@ -2,6 +2,12 @@ package com.indexdata.mkjsf.pazpar2.data; import com.indexdata.mkjsf.pazpar2.data.TermResponse; +/** + * Data from the termlist command, child object of TermListResponse + * + * @author Niels Erik + * + */ public class TermXTargetResponse extends TermResponse { private static final long serialVersionUID = 5201902652960804977L; @@ -10,19 +16,19 @@ public class TermXTargetResponse extends TermResponse { return getOneElement("id").getValue(); } public int getApproximation () { - return Integer.parseInt(getOneElement("approximation").getValue()); + return Integer.parseInt(getOneValue("approximation")); } public int getRecords () { - return Integer.parseInt(getOneElement("records").getValue()); + return Integer.parseInt(getOneValue("records")); } public int getFiltered () { - return Integer.parseInt(getOneElement("filtered").getValue()); + return Integer.parseInt(getOneValue("filtered")); } public String getState () { - return getOneElement("state").getValue(); + return getOneValue("state"); } public String getDiagnostic () { - return getOneElement("diagnostic").getValue(); + return getOneValue("diagnostic"); } } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/package-info.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/package-info.java new file mode 100644 index 0000000..d217761 --- /dev/null +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/package-info.java @@ -0,0 +1,18 @@ +/** + * Pazpar2 responses produced by Pazpar2 commands are parsed by the + * ResponseParser found in this package, the output being response data + * objects accessible to the UI. + * + *

The most recent responses from each command are accessible to the UI + * through the class Responses which is exposed to the UI as pzresp

+ * + *

Examples:

+ *
    + *
  • pzresp.show.hits returns a list of hits from the most recent show command
  • + *
  • pzresp.show.hits.[0] returns the first hit
  • + *
  • pzresp.show.hits.[0].author returns the author attribute of the first hit
  • + *
  • pzresp.show.hits.[0].getOneValue("my-hit-field") returns an arbitrary attribute of the data object
  • + *
+ * + */ +package com.indexdata.mkjsf.pazpar2.data; \ No newline at end of file diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/AuthResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/AuthResponse.java index 334bd15..8b8351c 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/AuthResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/AuthResponse.java @@ -1,5 +1,11 @@ package com.indexdata.mkjsf.pazpar2.data.sp; +/** + * Data from the auth command, can be accessed by pzresp.sp.auth + * + * @author Niels Erik + * + */ public class AuthResponse extends SpResponseDataObject { private static final long serialVersionUID = 8006774126022849936L; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/CategoriesResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/CategoriesResponse.java index 2f7ede9..efd2d5b 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/CategoriesResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/CategoriesResponse.java @@ -7,6 +7,12 @@ import javax.enterprise.context.SessionScoped; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; +/** + * Data from the categories command, can be accessed by pzresp.sp.categories + * + * @author Niels Erik + * + */ @SessionScoped public class CategoriesResponse extends SpResponseDataObject { diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/TargetCategory.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/TargetCategory.java index fd00a23..56f5606 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/TargetCategory.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/TargetCategory.java @@ -2,6 +2,12 @@ package com.indexdata.mkjsf.pazpar2.data.sp; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; +/** + * Data from the categories command, can be accessed by pzresp.sp.categories.targetCategories + * + * @author Niels Erik + * + */ public class TargetCategory extends ResponseDataObject { private static final long serialVersionUID = -3027515807117682584L; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/package-info.java b/src/main/java/com/indexdata/mkjsf/pazpar2/package-info.java index 640b810..b8e931a 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/package-info.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/package-info.java @@ -1,9 +1,9 @@ /** * Overall control and execution of search logic. *

- * Classes in this package selects a service type and controls and performs - * the actual execution of commands against the selected service, eventually producing - * ClientCommandResponses for further processing elsewhere. + * Classes in this package are used for defining a service type, setting a service URL + * and controlling and executing commands against the selected service, + * eventually producing ClientCommandResponses for further processing elsewhere. *

*/ package com.indexdata.mkjsf.pazpar2; \ No newline at end of file -- 1.7.10.4