import org.apache.myfaces.custom.fileupload.UploadedFile;\r
\r
import com.indexdata.mkjsf.config.ConfigurationReader;\r
-import com.indexdata.mkjsf.pazpar2.commands.CommandParameter;\r
-import com.indexdata.mkjsf.pazpar2.commands.sp.AuthCommand;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.InitDocUpload;\r
import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
-import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse;\r
-import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject;\r
import com.indexdata.mkjsf.utils.Utils;\r
\r
@Named("pz2x") @SessionScoped\r
// TODO: \r
//stateMgr.addStateListener(this);\r
}\r
- \r
- public void authenticate() { \r
- if (Pz2Bean.get().getPzresp().getSp().getAuth().unsupportedCommand()) {\r
- logger.warn("Running seemingly unsupported command [auth] against SP.");\r
- }\r
- Pz2Bean.get().resetSearchAndRecordCommands();\r
- Pz2Bean.get().getPzresp().getSp().resetAuthAndBeyond(true);\r
- Pz2Bean.get().getPzreq().getSp().getAuth().run();\r
- }\r
- \r
- public void login(String un, String pw) { \r
- login(un,pw,"");\r
- }\r
- \r
- public void login(String un, String pw, String navigateTo) { \r
- Pz2Bean.get().getPzreq().getSp().getAuth().setUsername(un);\r
- Pz2Bean.get().getPzreq().getSp().getAuth().setPassword(pw);\r
- login("");\r
- } \r
- \r
- @Override \r
- public String login(String navigateTo) {\r
- AuthCommand auth = Pz2Bean.get().getPzreq().getSp().getAuth(); \r
- auth.setParameterInState(new CommandParameter("action","=","login"));\r
- authenticate();\r
- return navigateTo;\r
- }\r
- \r
- public void ipAuthenticate () { \r
- AuthCommand auth = Pz2Bean.get().getPzreq().getSp().getAuth(); \r
- auth.setParameterInState(new CommandParameter("action","=","ipAuth"));\r
- authenticate();\r
- }\r
- \r
+ \r
public String getInitDocPath () {\r
return Pz2Bean.get().getSpClient().getConfiguration().get("INIT_DOC_PATH");\r
}\r
\r
@Override\r
public void setInitFileName(String fileName) {\r
- this.initDocFileName = fileName;\r
- \r
+ this.initDocFileName = fileName; \r
}\r
\r
@Override\r
return initDocUpload;\r
}\r
\r
- public CategoriesResponse getCategories () { \r
- String command="categories";\r
- if (Pz2Bean.get().isServiceProxyService()) {\r
- if (Pz2Bean.get().getPzresp().getSp().getCategories().unsupportedCommand()) {\r
- logger.info("Skipping seemingly unsupported command: " + command); \r
- return new CategoriesResponse();\r
- } else {\r
- SpResponseDataObject response = (SpResponseDataObject) Pz2Bean.get().getPzreq().getSp().getCategories().run();\r
- if (response.unsupportedCommand()) {\r
- logger.warn("Command 'categories' not supported by this Service Proxy"); \r
- } else if (response.hasApplicationError()) {\r
- logger.error(response.getXml()); \r
- } \r
- try {\r
- return (CategoriesResponse) response;\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- logger.debug(response.getXml());\r
- return new CategoriesResponse();\r
- }\r
- }\r
- } else {\r
- return new CategoriesResponse();\r
- }\r
- }\r
- \r
- \r
+ \r
}\r
import java.io.UnsupportedEncodingException;\r
\r
\r
-public interface ServiceProxyInterface { \r
- public String login(String navigateTo); \r
+public interface ServiceProxyInterface { \r
public void setInitFileName (String fileName); \r
public String getInitFileName();\r
public HttpResponseWrapper postInit() throws UnsupportedEncodingException, IOException;\r
import java.io.Serializable;\r
import java.util.HashMap;\r
import java.util.Map;\r
+import java.util.StringTokenizer;\r
\r
import org.apache.log4j.Logger;\r
\r
return name;\r
}\r
\r
- public ResponseDataObject run() {\r
+ public ResponseDataObject run() { \r
return run(Pz2Bean.get().getSearchClient(),\r
Pz2Bean.get().getPzresp());\r
}\r
\r
+ public ResponseDataObject runWith(String... parameters) {\r
+ for (String parameter : parameters) {\r
+ StringTokenizer tokenizer = new StringTokenizer(parameter,"=");\r
+ String name = (String) tokenizer.nextElement();\r
+ String value = (String) tokenizer.nextElement();\r
+ CommandParameter commandParameter = new CommandParameter(name,"=",value);\r
+ setParameterInState(commandParameter);\r
+ }\r
+ return run();\r
+ }\r
+ \r
/**\r
* For running the command in a thread. Client and Responses must be \r
* provided because at this point the CDI bean cannot be retrieved \r
* @return\r
*/\r
public ResponseDataObject run(SearchClient client,Responses pzresp) {\r
- logger.info("Running " + getCommandName() + " using " + client); \r
+ logger.debug("Running " + getCommandName() + " using " + client); \r
HttpResponseWrapper httpResponse = client.executeCommand(this);\r
logger.debug("Parsing response for " + getCommandName());\r
ResponseDataObject responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse) httpResponse);\r
Pz2Bean.get().getStateMgr().checkIn(command);\r
}\r
\r
+ public String navigateTo (String target) {\r
+ return target;\r
+ }\r
+ \r
public abstract ServiceProxyCommand getSp();\r
\r
public abstract boolean spOnly(); \r
}\r
\r
public SpResponseDataObject run() {\r
+ Pz2Bean.get().resetSearchAndRecordCommands();\r
+ Pz2Bean.get().getPzresp().getSp().resetAuthAndBeyond(true);\r
ClientCommandResponse response = (ClientCommandResponse) Pz2Bean.get().getSearchClient().executeCommand(this); \r
String renamedResponse = renameResponseElement(response.getResponseString(), "auth"); \r
response.setResponseToParse(renamedResponse);\r
package com.indexdata.mkjsf.pazpar2.commands.sp;\r
\r
+import org.apache.log4j.Logger;\r
+\r
+import com.indexdata.mkjsf.pazpar2.Pz2Bean;\r
import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
+import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse;\r
\r
public class CategoriesCommand extends Pazpar2Command implements ServiceProxyCommand {\r
\r
private static final long serialVersionUID = 5023993689780291641L;\r
+ private static Logger logger = Logger.getLogger(CategoriesCommand.class);\r
\r
public CategoriesCommand() {\r
super("categories");\r
}\r
+ \r
+ @Override\r
+ public CategoriesResponse run () {\r
+ if (Pz2Bean.get().getPzresp().getSp().getCategories().unsupportedCommand()) {\r
+ logger.info("Skipping seemingly unsupported categories command"); \r
+ return new CategoriesResponse();\r
+ } else {\r
+ if (Pz2Bean.get().isServiceProxyService()) {\r
+ try {\r
+ CategoriesResponse response = (CategoriesResponse) super.run();\r
+ if (response.unsupportedCommand()) {\r
+ logger.warn("Command 'categories' not supported by this Service Proxy"); \r
+ }\r
+ return response;\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ return new CategoriesResponse();\r
+ }\r
+ } else {\r
+ return new CategoriesResponse();\r
+ }\r
+ }\r
+ }\r
\r
@Override\r
public Pazpar2Command copy() {\r