\r
import com.indexdata.masterkey.config.MasterkeyConfiguration;\r
import com.indexdata.masterkey.config.ModuleConfiguration;\r
+import com.indexdata.pz2utils4jsf.utils.Utils;\r
\r
@Named @SessionScoped @Alternative\r
public class Pz2ConfigureByMk2Config implements Pz2Configurator {\r
private Pz2Config pz2config = null;\r
\r
public Pz2ConfigureByMk2Config () throws IOException {\r
- logger.debug("Instantiating Pazpar2 service configuration by MasterKey configuration scheme.");\r
- ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();\r
- ServletContext servletContext = (ServletContext) externalContext.getContext(); \r
- MasterkeyConfiguration mkConfigContext =\r
- MasterkeyConfiguration.getInstance(servletContext,\r
- "faces-component", ((HttpServletRequest) externalContext.getRequest()).getServerName());\r
- ModuleConfiguration moduleConfig = mkConfigContext.getModuleConfiguration("pz2client"); \r
- String pazpar2Url = moduleConfig.get("PAZPAR2_URL");\r
- String pazpar2ServiceId = moduleConfig.get("PAZPAR2_SERVICE_ID");\r
- pz2config = new Pz2Config(pazpar2Url,pazpar2ServiceId);\r
+ logger.info(Utils.objectId(this) + " is instantiating Pazpar2 service configuration by MasterKey configuration scheme.");\r
}\r
\r
@Override\r
- public Pz2Config getConfig() {\r
+ public Pz2Config getConfig() throws IOException {\r
+ if (pz2config == null) {\r
+ createConfig();\r
+ }\r
return pz2config;\r
}\r
\r
+ private void createConfig () throws IOException {\r
+ ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();\r
+ ServletContext servletContext = (ServletContext) externalContext.getContext(); \r
+ MasterkeyConfiguration mkConfigContext =\r
+ MasterkeyConfiguration.getInstance(servletContext,\r
+ "pazpar-application-jsf", ((HttpServletRequest) externalContext.getRequest()).getServerName());\r
+ ModuleConfiguration moduleConfig = mkConfigContext.getModuleConfiguration("pz2client");\r
+ pz2config = new Pz2Config(moduleConfig);\r
+ logger.info("Accessing Pazpar2 at: " +pz2config.get("PAZPAR2_URL"));\r
+ if (pz2config.get("PAZPAR2_SERVICE_XML") != null) {\r
+ logger.info("Using the service definition contained in " + pz2config.getConfigFilePath() + "/" + pz2config.get("PAZPAR2_SERVICE_XML"));\r
+ if (pz2config.get("PAZPAR2_SETTINGS_XML") != null) {\r
+ logger.info("Using the target settings contained in " + pz2config.getConfigFilePath() + "/" + pz2config.get("PAZPAR2_SETTINGS_XML"));\r
+ } else {\r
+ logger.info("Using the server side target settings as defined in the service definition.");\r
+ }\r
+ } else if (pz2config.get("PAZPAR2_SERVICE_ID") != null) {\r
+ logger.info("Using the server side service definition identified by service id "+pz2config.get("PAZPAR2_SERVICE_ID"));\r
+ } else {\r
+ logger.error("Did not find service ID nor service definition XML file so set up pazpar2 service.");\r
+ }\r
+\r
+ }\r
+ \r
\r
}\r