errors.addConfigurationError(new ConfigurationError("Search Client","Configuration",e.getMessage())); \r
} \r
logger.info(configReader.document());\r
- pzresp.reset(); \r
+ pzresp.resetAllSessionData(); \r
}\r
\r
- public void resetSearchAndResults () {\r
+ public void resetSearchAndRecordCommands () {\r
pzreq.getRecord().removeParametersInState();\r
- pzreq.getSearch().removeParametersInState();\r
- pzresp.reset(); \r
+ pzreq.getSearch().removeParametersInState(); \r
}\r
\r
\r
\r
public void doSearch() { \r
stateMgr.hasPendingStateChange("search",false);\r
- pzresp.reset();\r
+ pzresp.resetSearchResponses();\r
// resets some record and show command parameters without \r
// changing state or creating state change feedback\r
pzreq.getRecord().removeParametersInState(); \r
} \r
} else {\r
logger.debug("Skipped requests for " + commands + " as there's not yet a query."); \r
- pzresp.reset();\r
+ pzresp.resetSearchResponses();\r
return "0";\r
}\r
} else {\r
if (url!=null && searchClient != null && !url.equals(searchClient.getServiceUrl())) {\r
pzreq.getRecord().removeParametersInState();\r
pzreq.getSearch().removeParametersInState();\r
- pzresp.reset();\r
+ pzresp.resetAllSessionData();\r
user.clear();\r
searchClient.setServiceUrl(url);\r
} \r
private void setServiceType(String type) {\r
if (!serviceType.equals(type) &&\r
!serviceType.equals(SERVICE_TYPE_TBD)) {\r
- resetSearchAndResults();\r
+ resetSearchAndRecordCommands();\r
+ pzresp.resetAllSessionData();\r
}\r
serviceType = type;\r
if (serviceType.equals(SERVICE_TYPE_PZ2)) {\r
import javax.inject.Named;\r
\r
import org.apache.log4j.Logger;\r
+import org.apache.myfaces.custom.fileupload.UploadedFile;\r
\r
import com.indexdata.mkjsf.config.ConfigurationReader;\r
import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Commands;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.InitDocUpload;\r
+import com.indexdata.mkjsf.pazpar2.data.InitResponse;\r
+import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
+import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
import com.indexdata.mkjsf.pazpar2.data.Responses;\r
import com.indexdata.mkjsf.pazpar2.sp.auth.ServiceProxyUser;\r
+import com.indexdata.mkjsf.utils.Utils;\r
\r
@Named("pz2x") @SessionScoped\r
-public class ServiceProxyExtensions implements ServiceProxyInterface, Serializable {\r
+public class ServiceProxyExtensions implements ServiceProxyInterface, Serializable {\r
\r
private static final long serialVersionUID = 4221824985678758225L;\r
private static Logger logger = Logger.getLogger(ServiceProxyExtensions.class); \r
@Override\r
public String login(String navigateTo) {\r
logger.info("doing login by " + user + " using " + pz2 + " and client " + pz2.getSpClient());\r
- pz2.getSpClient().authenticate(user);\r
- pz2.resetSearchAndResults();\r
+ pz2.resetSearchAndRecordCommands();\r
+ pzresp.resetAllSessionData();\r
+ pz2.getSpClient().authenticate(user); \r
return navigateTo;\r
}\r
\r
if (user.isAuthenticated()) {\r
user.clear();\r
}\r
- pz2.resetSearchAndResults();\r
+ pz2.resetSearchAndRecordCommands();\r
+ pzresp.resetAllSessionData();\r
pz2.getSpClient().ipAuthenticate(user);\r
}\r
}\r
String initDocPath = pz2.getSpClient().getInitDocPaths().get(0);\r
logger.info("Paths: " + pz2.getSpClient().getInitDocPaths());\r
logger.info("Path: " + initDocPath);\r
- pz2.resetSearchAndResults();\r
+ pz2.resetSearchAndRecordCommands();\r
+ pzresp.resetAllSessionData();\r
ClientCommandResponse response = pz2.getSpClient().postInitDoc(initDocPath + getInitFileName()); \r
return response;\r
}\r
\r
@Override\r
public ClientCommandResponse postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException { \r
- pz2.resetSearchAndResults();\r
+ pz2.resetSearchAndRecordCommands();\r
+ pzresp.resetAllSessionData();\r
ClientCommandResponse response = pz2.getSpClient().postInitDoc(initDoc,includeDebug); \r
return response;\r
}\r
return initDocResponse;\r
}\r
\r
+ public void setUploadedInitDoc (UploadedFile uploadedFile) {\r
+ initDocUpload.setUploadedFile(uploadedFile);\r
+ }\r
+ \r
+ public UploadedFile getUploadedInitDoc () {\r
+ return initDocUpload.getUploadedFile();\r
+ }\r
+ \r
+ public void submitInitDoc () throws IOException {\r
+ HttpResponseWrapper response = initDocUpload.submit();\r
+ ResponseDataObject responseObject = ResponseParser.getParser().getDataObject(response.getResponseString());\r
+ logger.info("Putting init response to : " + Utils.objectId(pzresp));\r
+ pzresp.put("init", responseObject);\r
+ }\r
+ \r
+ public void setIncludeInitDocDebug(boolean bool) {\r
+ logger.info(Utils.objectId(this) + " setting debug to " + bool);\r
+ initDocUpload.setIncludeDebug(bool);\r
+ }\r
+\r
+ public boolean getIncludeInitDocDebug() {\r
+ return initDocUpload.getIncludeDebug();\r
+ }\r
+ \r
+ // TODO: Remove when possible\r
public InitDocUpload getInitDocUpload () {\r
return initDocUpload;\r
}\r
+\r
+ \r
+ \r
\r
}\r
import javax.inject.Named;\r
\r
import org.apache.log4j.Logger;\r
+import org.apache.myfaces.custom.fileupload.UploadedFile;\r
\r
+import com.indexdata.mkjsf.pazpar2.ClientCommandResponse;\r
+import com.indexdata.mkjsf.pazpar2.HttpResponseWrapper;\r
import com.indexdata.mkjsf.pazpar2.ServiceProxyExtensions;\r
import com.indexdata.mkjsf.utils.FileUpload;\r
import com.indexdata.mkjsf.utils.Utils;\r
@SessionScoped\r
public class InitDocUpload extends FileUpload {\r
\r
+ \r
+ private UploadedFile uploadedFile = null;\r
private static Logger logger = Logger.getLogger(InitDocUpload.class);\r
private static final long serialVersionUID = 1846749236304941323L; \r
private boolean includeDebug = false;\r
- private ServiceProxyExtensions spBean;\r
+ private ServiceProxyExtensions spBean; \r
\r
public InitDocUpload(ServiceProxyExtensions spBean) {\r
this.spBean = spBean;\r
}\r
\r
- public String submit() throws IOException {\r
+ public HttpResponseWrapper submit() throws IOException {\r
logger.info(Utils.objectId(this) + " submitting");\r
- //String fileName = FilenameUtils.getName(uploadedFile.getName());\r
- //String contentType = uploadedFile.getContentType();\r
byte[] bytes = uploadedFile.getBytes();\r
response = spBean.postInit(bytes, includeDebug);\r
- return "";\r
+ return response;\r
+ }\r
+ \r
+ public UploadedFile getUploadedFile() {\r
+ return uploadedFile;\r
}\r
\r
+ public void setUploadedFile(UploadedFile uploadedFile) {\r
+ logger.info(Utils.objectId(this) + " received an uploaded file [" + Utils.objectId(uploadedFile) + "]");\r
+ this.uploadedFile = uploadedFile;\r
+ }\r
+\r
+\r
public void setIncludeDebug(boolean bool) {\r
logger.info(Utils.objectId(this) + " setting debug to " + bool);\r
includeDebug = bool;\r
\r
private static final long serialVersionUID = -1479775157276901600L;\r
\r
- public InitResponse() {\r
- // TODO Auto-generated constructor stub\r
+ public String getStatus() {\r
+ return getOneElementValue("status");\r
}\r
\r
}\r
import org.xml.sax.XMLReader;\r
import org.xml.sax.helpers.DefaultHandler;\r
\r
-import com.indexdata.mkjsf.pazpar2.data.ByTarget;\r
-import com.indexdata.mkjsf.pazpar2.data.Hit;\r
-import com.indexdata.mkjsf.pazpar2.data.Location;\r
-import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
-import com.indexdata.mkjsf.pazpar2.data.RecordResponse;\r
-import com.indexdata.mkjsf.pazpar2.data.ShowResponse;\r
-import com.indexdata.mkjsf.pazpar2.data.StatResponse;\r
-import com.indexdata.mkjsf.pazpar2.data.Target;\r
-import com.indexdata.mkjsf.pazpar2.data.TermListResponse;\r
-import com.indexdata.mkjsf.pazpar2.data.TermListsResponse;\r
-import com.indexdata.mkjsf.pazpar2.data.TermResponse;\r
-import com.indexdata.mkjsf.pazpar2.data.TermXTargetResponse;\r
-\r
public class ResponseParser extends DefaultHandler {\r
\r
private XMLReader xmlReader = null;\r
private static Logger logger = Logger.getLogger(ResponseParser.class);\r
\r
public static final List<String> docTypes = \r
- Arrays.asList("bytarget","termlist","show","stat","record","search");\r
+ Arrays.asList("bytarget","termlist","show","stat","record","search","init");\r
\r
public ResponseParser() { \r
try {\r
*/\r
@Override\r
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {\r
- if (localName.equals("show")) {\r
+ if (localName.equals("init")) {\r
+ currentElement = new InitResponse();\r
+ } else if (localName.equals("search")) {\r
+ currentElement = new SearchResponse();\r
+ } else if (localName.equals("show")) {\r
currentElement = new ShowResponse(); \r
} else if (localName.equals("hit")) {\r
currentElement = new Hit();\r
} else if (localName.equals("location")) {\r
currentElement = new Location();\r
+ } else if (localName.equals("record")) {\r
+ currentElement = new RecordResponse(); \r
} else if (localName.equals("bytarget")) {\r
currentElement = new ByTarget(); \r
} else if (localName.equals("target")) {\r
currentElement = new TermResponse();\r
}\r
((TermListResponse)dataElements.peek()).addTerm((TermResponse)currentElement);\r
- } else if (localName.equals("record")) {\r
- currentElement = new RecordResponse(); \r
- } else if (localName.equals("search")) {\r
- currentElement = new SearchResponse();\r
} else if (localName.equals("applicationerror")) {\r
currentElement = new CommandError();\r
} else if (localName.equals("error") && dataElements.peek().getType().equals("applicationerror")) {\r
import com.indexdata.mkjsf.errors.ErrorHelper;\r
import com.indexdata.mkjsf.errors.ErrorInterface;\r
import com.indexdata.mkjsf.pazpar2.data.sp.SpResponses;\r
+import com.indexdata.mkjsf.utils.Utils;\r
\r
@Named("pzresp") @SessionScoped\r
public class Responses implements Serializable {\r
return error; \r
}\r
\r
- public void reset() {\r
- logger.debug("Resetting show,stat,termlist,bytarget,search response objects.");\r
- dataObjects = new ConcurrentHashMap<String,ResponseDataObject>();\r
+ public void resetSearchResponses() {\r
+ logger.debug("Resetting show,stat,termlist,bytarget,record,search response objects.");\r
dataObjects.put("show", new ShowResponse());\r
dataObjects.put("stat", new StatResponse());\r
dataObjects.put("termlist", new TermListsResponse());\r
dataObjects.put("bytarget", new ByTarget());\r
dataObjects.put("record", new RecordResponse());\r
- dataObjects.put("search", new SearchResponse());\r
+ dataObjects.put("search", new SearchResponse()); \r
+ }\r
+ \r
+ public void resetAllSessionData () {\r
+ logger.debug("Resetting all response objects");\r
+ dataObjects = new ConcurrentHashMap<String,ResponseDataObject>(); \r
+ resetSearchResponses();\r
+ dataObjects.put("init", new InitResponse());\r
+ }\r
+ \r
+ public InitResponse getInit () {\r
+ logger.info("Request to show init response from " + Utils.objectId(this));\r
+ return ((InitResponse) dataObjects.get("init"));\r
}\r
\r
public ShowResponse getShow () {\r
\r
private static final long serialVersionUID = -3320013021497018972L;\r
\r
+ public String getStatus() {\r
+ return getOneElementValue("status");\r
+ }\r
+\r
}\r
\r
public abstract class FileUpload implements Serializable {\r
\r
- protected UploadedFile uploadedFile;\r
+\r
protected HttpResponseWrapper response;\r
private static Logger logger = Logger.getLogger(FileUpload.class);\r
private static final long serialVersionUID = 748784638056392862L;\r
public FileUpload() {\r
}\r
\r
- public abstract String submit() throws IOException;\r
+ public abstract HttpResponseWrapper submit() throws IOException;\r
\r
- public UploadedFile getUploadedFile() {\r
- return uploadedFile;\r
- }\r
-\r
- public void setUploadedFile(UploadedFile uploadedFile) {\r
- logger.info(Utils.objectId(this) + " received an uploaded file [" + Utils.objectId(uploadedFile) + "]");\r
- this.uploadedFile = uploadedFile;\r
- }\r
+ public abstract UploadedFile getUploadedFile();\r
+ \r
+ public abstract void setUploadedFile(UploadedFile uploadedFile);\r
\r
public void downloadDoc() throws IOException {\r
logger.info(Utils.objectId(this) + " got a download request");\r
FacesContext facesContext = FacesContext.getCurrentInstance();\r
ExternalContext externalContext = facesContext.getExternalContext();\r
- externalContext.setResponseHeader("Content-Type", uploadedFile.getContentType());\r
- externalContext.setResponseHeader("Content-Length", String.valueOf((uploadedFile.getBytes().length)));\r
- externalContext.setResponseHeader("Content-Disposition", "attachment;filename=\"" + FilenameUtils.getBaseName(uploadedFile.getName()) + "\"");\r
- externalContext.getResponseOutputStream().write(uploadedFile.getBytes());\r
+ externalContext.setResponseHeader("Content-Type", getUploadedFile().getContentType());\r
+ externalContext.setResponseHeader("Content-Length", String.valueOf((getUploadedFile().getBytes().length)));\r
+ externalContext.setResponseHeader("Content-Disposition", "attachment;filename=\"" + FilenameUtils.getBaseName(getUploadedFile().getName()) + "\"");\r
+ externalContext.getResponseOutputStream().write(getUploadedFile().getBytes());\r
facesContext.responseComplete();\r
}\r
\r