From 17d3168e6fec9a87936aee992ac1a5deaad49cfe Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Mon, 4 Mar 2013 13:12:03 -0500 Subject: [PATCH] Adds injectable pazpar2 client configs To allow users of the toolkit a freedom of choice regarding configuration scheme (ie web.xml, property file, masterkey configuration scheme, etc) --- pom.xml | 10 +++++--- src/META-INF/context.xml | 4 +-- .../indexdata/pz2utils4jsf/config/Pz2Config.java | 8 +++++- .../pz2utils4jsf/config/Pz2ConfigureByWebXml.java | 5 ++-- .../indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java | 27 ++++++++++++-------- .../pz2utils4jsf/pazpar2/Pz2Interface.java | 3 ++- .../indexdata/pz2utils4jsf/pazpar2/Pz2Session.java | 27 ++++++++++++++------ 7 files changed, 56 insertions(+), 28 deletions(-) diff --git a/pom.xml b/pom.xml index 58d2ff2..42a9c9a 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,7 @@ com.indexdata masterkey-common - 0.1.9-SNAPSHOT + 0.1.10-SNAPSHOT @@ -47,8 +47,9 @@ src - - **/*.java + + main/ + *.java @@ -57,6 +58,9 @@ maven-compiler-plugin 2.3.2 + + src/META-INF/ + 1.7 1.7 diff --git a/src/META-INF/context.xml b/src/META-INF/context.xml index 7f18535..c4ecc5d 100644 --- a/src/META-INF/context.xml +++ b/src/META-INF/context.xml @@ -4,6 +4,6 @@ auth="Container" type="javax.enterprise.inject.spi.BeanManager" factory="org.jboss.weld.resources.ManagerObjectFactory"/> - WEB-INF/web.xml - META-INF/context.xml + \ No newline at end of file diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Config.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Config.java index 3caa832..fc3c538 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Config.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Config.java @@ -1,13 +1,18 @@ package com.indexdata.pz2utils4jsf.config; +import java.io.Serializable; import java.util.HashMap; import java.util.Map; +import org.apache.log4j.Logger; + import com.indexdata.masterkey.config.MissingMandatoryParameterException; import com.indexdata.masterkey.config.ModuleConfigurationGetter; -public class Pz2Config implements ModuleConfigurationGetter { +public class Pz2Config implements ModuleConfigurationGetter, Serializable { + private static final long serialVersionUID = -6801241975338182197L; + private static Logger logger = Logger.getLogger(Pz2Config.class); Map properties = new HashMap(); public Pz2Config () { @@ -18,6 +23,7 @@ public class Pz2Config implements ModuleConfigurationGetter { setStatics(); setPazpar2Url(pazpar2Url); setPazpar2ServiceId(pazpar2ServiceId); + logger.debug("Creating pazpar2 configuration with "+ get("PAZPAR2_URL") + " and " + get("PAZPAR2_SERVICE_ID")); } private void setStatics () { diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java index 9a225b0..92ea7d8 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java @@ -8,8 +8,7 @@ import javax.servlet.ServletContext; import org.apache.log4j.Logger; -@Named("pz2configwebxml") -@SessionScoped +@SessionScoped @Named public class Pz2ConfigureByWebXml implements Pz2Configurator { private static final long serialVersionUID = 144390224959311772L; @@ -21,7 +20,7 @@ public class Pz2ConfigureByWebXml implements Pz2Configurator { ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); ServletContext servletContext = (ServletContext) externalContext.getContext(); String pazpar2Url = servletContext.getInitParameter("PAZPAR2_URL"); - String pazpar2ServiceId = servletContext.getInitParameter("PAZPAR2_SERVICE_id"); + String pazpar2ServiceId = servletContext.getInitParameter("PAZPAR2_SERVICE_ID"); config = new Pz2Config(pazpar2Url,pazpar2ServiceId); } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java index c139786..e5cfb1c 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java @@ -3,15 +3,15 @@ package com.indexdata.pz2utils4jsf.pazpar2; import java.io.Serializable; import java.util.List; +import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; import javax.inject.Inject; import javax.inject.Named; -import com.indexdata.pz2utils4jsf.config.Pz2ConfigureByWebXml; +import org.apache.log4j.Logger; + +import com.indexdata.pz2utils4jsf.config.Pz2Configurator; import com.indexdata.pz2utils4jsf.controls.ResultsPager; -import com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface; -import com.indexdata.pz2utils4jsf.pazpar2.Pz2Session; -import com.indexdata.pz2utils4jsf.pazpar2.TargetFilter; import com.indexdata.pz2utils4jsf.pazpar2.data.ByTarget; import com.indexdata.pz2utils4jsf.pazpar2.data.RecordResponse; import com.indexdata.pz2utils4jsf.pazpar2.data.ShowResponse; @@ -24,14 +24,21 @@ import com.indexdata.pz2utils4jsf.pazpar2.data.TermResponse; public class Pz2Bean implements Pz2Interface, Serializable { private static final long serialVersionUID = 3440277287081557861L; - Pz2Session pz2; - - @Inject - private Pz2ConfigureByWebXml pz2conf; - + private static Logger logger = Logger.getLogger(Pz2Bean.class); + + Pz2Session pz2; + @Inject Pz2Configurator pz2conf; + public Pz2Bean () { - pz2 = new Pz2Session(pz2conf); + logger.debug("Instantiating pz2 bean"); + pz2 = new Pz2Session(); + } + + @PostConstruct + public void initiatePz2Session() { + pz2.init(pz2conf); } + /* (non-Javadoc) * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#doSearch(java.lang.String) */ diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java index 6aa1921..8f6153a 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java @@ -1,5 +1,6 @@ package com.indexdata.pz2utils4jsf.pazpar2; +import java.io.Serializable; import java.util.List; import com.indexdata.pz2utils4jsf.controls.ResultsPager; @@ -11,7 +12,7 @@ import com.indexdata.pz2utils4jsf.pazpar2.data.StatResponse; import com.indexdata.pz2utils4jsf.pazpar2.data.TermListsResponse; import com.indexdata.pz2utils4jsf.pazpar2.data.TermResponse; -public interface Pz2Interface { +public interface Pz2Interface extends Serializable { /** * Executes a Pazpar2 search using the given query string diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java index 53e542d..b4323fc 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java @@ -1,12 +1,14 @@ package com.indexdata.pz2utils4jsf.pazpar2; -import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import java.util.concurrent.ConcurrentHashMap; +import javax.enterprise.context.SessionScoped; +import javax.inject.Named; + import org.apache.log4j.Logger; import com.indexdata.masterkey.pazpar2.client.exceptions.ProxyErrorException; @@ -22,7 +24,9 @@ import com.indexdata.pz2utils4jsf.pazpar2.data.TermListsResponse; import com.indexdata.pz2utils4jsf.pazpar2.data.TermResponse; import com.indexdata.pz2utils4jsf.pazpar2.state.QueryStates; -public class Pz2Session implements Serializable, Pz2Interface { +@Named +@SessionScoped +public class Pz2Session implements Pz2Interface { private static Logger logger = Logger.getLogger(Pz2Session.class); @@ -34,19 +38,26 @@ public class Pz2Session implements Serializable, Pz2Interface { private com.indexdata.masterkey.pazpar2.client.Pazpar2Client client = null; private TargetFilter targetFilter = null; private ResultsPager pager = null; - - public Pz2Session (Pz2Configurator pz2conf) { - logger.debug("Instantiating pz2"); - if (pz2conf == null) {logger.error("conf is null!!!!!!!!!!!!!!!"); } + + public Pz2Session () { + logger.debug("Instantiating pz2 session object"); + } + + public void init(Pz2Configurator pz2conf) { + if (client==null) { + logger.debug("Initiating a session holding object "); try { cfg = new com.indexdata.masterkey.pazpar2.client.Pazpar2ClientConfiguration(pz2conf.getConfig()); client = new com.indexdata.masterkey.pazpar2.client.Pazpar2ClientGeneric(cfg); resetDataObjects(); } catch (ProxyErrorException e) { e.printStackTrace(); - } + } + } else { + logger.error("??? attempt to initiate session but already has a client"); + } } - + public void doSearch(String query) { setCommandParameter("search",new CommandParameter("query","=",query)); doSearch(); -- 1.7.10.4