1 package com.indexdata.mkjsf.pazpar2;
\r
3 import java.io.IOException;
\r
4 import java.io.UnsupportedEncodingException;
\r
5 import java.util.ArrayList;
\r
6 import java.util.List;
\r
8 import javax.annotation.PostConstruct;
\r
9 import javax.enterprise.context.SessionScoped;
\r
10 import javax.enterprise.inject.Alternative;
\r
11 import javax.inject.Inject;
\r
12 import javax.inject.Named;
\r
14 import org.apache.log4j.Logger;
\r
16 import com.indexdata.mkjsf.config.ConfigurationReader;
\r
17 import com.indexdata.mkjsf.pazpar2.sp.ServiceProxyClient;
\r
18 import com.indexdata.mkjsf.pazpar2.sp.ServiceProxyCommandResponse;
\r
19 import com.indexdata.mkjsf.pazpar2.sp.ServiceProxyInterface;
\r
20 import com.indexdata.mkjsf.pazpar2.sp.auth.ServiceProxyUser;
\r
21 import com.indexdata.mkjsf.utils.Utils;
\r
23 @Named("pz2") @SessionScoped @Alternative
\r
24 public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface {
\r
26 private static final long serialVersionUID = 4221824985678758225L;
\r
27 private static Logger logger = Logger.getLogger(Pz2ProxyBean.class);
\r
28 private String initDocFileName = "";
\r
29 private String initDocResponse = "";
\r
31 @Inject ConfigurationReader configurator;
\r
32 @Inject ServiceProxyUser user;
\r
34 public Pz2ProxyBean() {
\r
38 public void postConstruct() {
\r
39 if (searchClient == null) {
\r
40 logger.debug(Utils.objectId(this) + " will instantiate a ServiceProxyClient next.");
\r
41 searchClient = new ServiceProxyClient();
\r
42 logger.info("Using [" + Utils.objectId(searchClient) + "] configured by ["
\r
43 + Utils.objectId(configurator) + "]" );
\r
44 configureClient(searchClient,configurator);
\r
45 stateMgr.addStateListener(this);
\r
47 logger.debug("Pz2ProxyBean:postConstruct: searchClient already instantiated " +
\r
48 "during construction of parent object Pz2Bean.");
\r
52 public void login(String un, String pw) {
\r
53 if (user.isAuthenticated() && user.getName().equals(un) && ((ServiceProxyClient) searchClient).checkAuthentication(user)) {
\r
54 logger.info("Repeat request from UI to authenticate user. Auth verified for given user name so skipping log-in.");
\r
56 logger.info("doing un/pw login");
\r
58 user.setPassword(pw);
\r
64 public String login(String navigateTo) {
\r
65 logger.info("doing login");
\r
66 ((ServiceProxyClient)searchClient).authenticate(user);
\r
67 pzreq.getRecord().removeParametersInState();
\r
68 pzreq.getSearch().removeParametersInState();
\r
73 public void ipAuthenticate (ServiceProxyUser user) {
\r
74 if (!user.isIpAuthenticated()) {
\r
75 if (user.isAuthenticated()) {
\r
78 pzreq.getRecord().removeParametersInState();
\r
79 pzreq.getSearch().removeParametersInState();
\r
81 ((ServiceProxyClient)searchClient).ipAuthenticate(user);
\r
86 public void setServiceProxyUrl(String url) {
\r
87 logger.info("Setting Service Proxy url: " + url);
\r
88 if (url!=null & !url.equals(((ServiceProxyClient)searchClient).getServiceProxyUrl())) {
\r
89 pzreq.getRecord().removeParametersInState();
\r
90 pzreq.getSearch().removeParametersInState();
\r
93 ((ServiceProxyClient)searchClient).setServiceProxyUrl(url);
\r
97 public String getServiceProxyUrl() {
\r
98 return ((ServiceProxyClient)searchClient).getServiceProxyUrl();
\r
101 public boolean getServiceProxyUrlIsDefined() {
\r
102 return ((ServiceProxyClient)searchClient).getServiceProxyUrl().length()>0;
\r
105 public List<String> getServiceProxyUrls() {
\r
106 List<String> urls = new ArrayList<String>();
\r
108 urls.addAll(((ServiceProxyClient)searchClient).getServiceProxyUrls());
\r
112 public String getInitDocPath () {
\r
113 return searchClient.getConfiguration().get("INIT_DOC_PATH");
\r
117 public void setInitFileName(String fileName) {
\r
118 this.initDocFileName = fileName;
\r
123 public String getInitFileName() {
\r
124 return initDocFileName;
\r
128 public ServiceProxyCommandResponse postInit() throws UnsupportedEncodingException, IOException {
\r
129 String initDocPath = ((ServiceProxyClient)searchClient).getInitDocPaths().get(0);
\r
130 logger.info("Paths: " + ((ServiceProxyClient)searchClient).getInitDocPaths());
\r
131 logger.info("Path: " + initDocPath);
\r
133 ServiceProxyCommandResponse response = ((ServiceProxyClient)searchClient).postInitDoc(initDocPath + getInitFileName());
\r
138 public ServiceProxyCommandResponse postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException {
\r
140 ServiceProxyCommandResponse response = ((ServiceProxyClient)searchClient).postInitDoc(initDoc,includeDebug);
\r
145 public String getInitResponse() {
\r
146 return initDocResponse;
\r