Author: stianh
Date: 2007-06-20 14:10:05 +0200 (Wed, 20 Jun 2007)
New Revision: 5364
Modified:
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/CatalogueResultHandler.java
Log:
GULD-519 Use index data when remote service fails.
Modified:
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/CatalogueResultHandler.java
===================================================================
---
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/CatalogueResultHandler.java
2007-06-20 11:34:15 UTC (rev 5363)
+++
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/CatalogueResultHandler.java
2007-06-20 12:10:05 UTC (rev 5364)
@@ -1,7 +1,11 @@
// Copyright (2006-2007) Schibsted Søk AS
+
package no.schibstedsok.searchportal.result.handler;
+import java.util.Collection;
import java.util.Properties;
+
+import javax.ejb.EJBException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import no.schibstedsok.alfa.external.service.CompanyService;
@@ -26,114 +30,140 @@
*/
public final class CatalogueResultHandler implements ResultHandler {
- private static final Logger LOG =
Logger.getLogger(CatalogueResultHandler.class);
-
+ /** Logger for this class. */
+ private static final Logger LOG =
Logger.getLogger(CatalogueResultHandler.class);
+
+ /** Configuration for this result handler. */
private final CatalogueResultHandlerConfig config;
-
+
/**
- *
- * @param config
+ * Constructor.
+ * @param config The configuration for the result handler.
*/
- public CatalogueResultHandler(final ResultHandlerConfig config){
- this.config = (CatalogueResultHandlerConfig)config;
+ public CatalogueResultHandler(final ResultHandlerConfig config) {
+ this.config = (CatalogueResultHandlerConfig) config;
}
- /** [EMAIL PROTECTED]
- */
- public void handleResult(final Context cxt, final DataModel datamodel) {
-
- LOG.info("Starter Catalogue ResultHandler.");
+ /**
+ * Responsible for enrich the search result with data from a remote
service.
+ * If the remote service is not available, the index data will be used.
+ *
+ * @see
ResultHandler#handleResult(no.schibstedsok.searchportal.result.handler.ResultHandler.Context,
DataModel)
+ * @param ctx The search context containing the search result.
+ * @param datamodel the datamodel containining the site configuration.
+ */
+ public void handleResult(final Context ctx, final DataModel datamodel) {
- final SiteConfiguration siteConf =
datamodel.getSite().getSiteConfiguration();
+ LOG.info("Starting Catalogue ResultHandler.");
- final String url = (String)
siteConf.getProperties().get("alfa_remote_service_url");
+ final SiteConfiguration siteConf =
datamodel.getSite().getSiteConfiguration();
+ final ResultList<ResultItem> searchResult = ctx.getSearchResult();
- final String jndi = (String)
siteConf.getProperties().get("alfa_remote_service_jndi_name");
+ if (searchResult.getResults().iterator().hasNext()) {
- final ResultList<ResultItem> searchResult =
cxt.getSearchResult();
+ final CatalogueSearchResultItem cat = (CatalogueSearchResultItem)
searchResult.getResults().get(0);
+ final int companyId =
Integer.valueOf(cat.getField("iypcompanyid"));
-
- if (searchResult.getResults().iterator().hasNext()) {
-
- final CatalogueSearchResultItem cat =
(CatalogueSearchResultItem) searchResult.getResults().get(0);
-
- final String sCompanyId = cat.getField("iypcompanyid");
-
- final int intCompanyId = Integer.valueOf(sCompanyId);
-
ProductSearchResult internalResult = null;
- no.schibstedsok.alfa.external.dto.ProductSearchResult eksternt =
null;
+ no.schibstedsok.alfa.external.dto.ProductSearchResult
companyServiceResult = null;
try {
- final Properties properties = new Properties();
- properties.put("java.naming.factory.initial",
- "org.jnp.interfaces.NamingContextFactory");
- properties.put("java.naming.factory.url.pkgs",
- "org.jboss.naming:org.jnp.interfaces");
- properties.put("java.naming.provider.url", url);
+ companyServiceResult =
(no.schibstedsok.alfa.external.dto.ProductSearchResult)
getCompanyService(siteConf).getProductDataForCompany(
+ companyId);
+ internalResult = new ProductSearchResult();
+ if (companyServiceResult.hasInfoPageProducts()) {
+ LOG.debug("Found info page products for companyId: "+
companyId);
+ for (no.schibstedsok.alfa.external.dto.ProductResultItem
externalProductResultItem : companyServiceResult.getInfoPageProducts()) {
- LOG.debug("Url: " + url);
- LOG.debug("JNDI_NAME: " + jndi);
- LOG.debug("CompanyId: " + intCompanyId);
+ final ProductResultItem item = new
ProductSearchResultItem();
- final InitialContext ctx = new InitialContext(properties);
-
- // hent ut remoteinterfacet til server side ejbn vi vil kalle
- final CompanyService service = (CompanyService)
ctx.lookup(jndi);
-
- // kall sl-bean i salesadmin with company id parameter.
- eksternt =
(no.schibstedsok.alfa.external.dto.ProductSearchResult) service
- .getProductDataForCompany(intCompanyId);
-
- } catch (NamingException ex) {
- LOG.error("Jndi-lookup failed, "+ex.getMessage(),ex);
- }
-
-
-
- /**
- * Hent ut alle produkter som er lagt inn på infosiden.
- */
- internalResult = new ProductSearchResult();
- if (eksternt.hasInfoPageProducts()) {
- LOG.debug("Fant info page products, hent ut.");
- for (no.schibstedsok.alfa.external.dto.ProductResultItem
prodItem : eksternt.getInfoPageProducts()) {
-
- final ProductResultItem item = new
ProductSearchResultItem();
-
- if (prodItem.getFields().size() > 0) {
- item.setFields(prodItem.getFields());
- LOG.info("Field: " + prodItem.getFields());
- internalResult.addInfoPageResult(item);
+ if (externalProductResultItem.getFields().size() > 0) {
+
item.setFields(externalProductResultItem.getFields());
+ LOG.info("Field: " +
externalProductResultItem.getFields());
+ internalResult.addInfoPageResult(item);
+ }
}
+ } else {
+ LOG.debug("No info page products for companyId: " +
companyId);
}
- } else {
- LOG.debug("Firmaet har ingen info page produkter.");
+ cat.addProducts(internalResult);
+ // the content enrichment was done from remote service, return.
+ return;
+ } catch (NamingException e) {
+ LOG.error("Unable to lookup remote service, index will be used
for info page result " , e);
+ } catch(EJBException e){
+ LOG.error("Error occured calling remote service, index will be
used for info page result ", e);
}
+
+ ProductSearchResult internalIndexResult = new
ProductSearchResult();
+
internalIndexResult.addInfoPageResult(createIndexInfoPageItem(cat));
+
+ //internalIndexResult.addInfoPageResult(indexInfoPageItem);
+ cat.addProducts(internalIndexResult);
+ }
+ }
+
+ /**
+ * Populate info page product based on index data.
+ * @param cat The search result item.
+ * @return The infopage product based on index data.
+ */
+ private ProductResultItem
createIndexInfoPageItem(CatalogueSearchResultItem cat) {
+ ProductResultItem indexInfoPageItem = new ProductSearchResultItem();
+
+ indexInfoPageItem.addField("businessname",
cat.getField("iypnavnvisning"));
+ indexInfoPageItem.addField("marketname",
cat.getField("iypnavnmarked"));
+ indexInfoPageItem.addField("organizationno", cat.getField("iyporgnr"));
+ indexInfoPageItem.addField("phone1", cat.getField("iypnrtelefon"));
+ indexInfoPageItem.addField("mobile",
cat.getField("iypnrtelefonmobil"));
+ indexInfoPageItem.addField("fax", cat.getField("iypnrfax"));
+ indexInfoPageItem.addField("email", cat.getField("iypepost"));
+ indexInfoPageItem.addField("logo", cat.getField("iyplogourl"));
+
+
+ indexInfoPageItem.addField("mapX", cat.getField("iypxcoord"));
+ indexInfoPageItem.addField("mapY", cat.getField("iypycoord"));
+ indexInfoPageItem.addField("homepage", cat.getField("iypurl"));
+
+ String postalAddress = cat.getField("iyppostadresse");
+ String postalZipCode = cat.getField("iyppostpostnr");
+ String postalCity = cat.getField("iyppostpostadresse");
+
+ if(postalAddress != null && postalAddress.length() > 0 &&
postalZipCode != null && postalZipCode.length() > 0 && postalCity != null &&
postalCity.length() > 0 ){
+ indexInfoPageItem.addField("fullPostalAddress", postalAddress + ",
" + postalZipCode + " " + postalCity);
+ }
+
+ String visitAddress = cat.getField("iypadresse");
+ String visitZipCode = cat.getField("iyppostnr");
+ String visitCity = cat.getField("iyppoststed");
+
+ if(visitAddress != null && visitAddress.length() > 0 && visitZipCode
!= null && visitZipCode.length() > 0 && visitCity != null && visitCity.length()
> 0 ){
+ indexInfoPageItem.addField("fullVisitAddress", visitAddress + ", "
+ visitZipCode + " " + visitCity);
+ }
+ return indexInfoPageItem;
+ }
+ /**
+ * Utility method for lookup of remote service.
+ *
+ * @param siteConf Configuration for url and jndi name of the service.
+ * @return Reference to a remote CompanyService reference.
+ * @throws NamingException If lookup of service in JNDI fails.
+ */
+ private CompanyService getCompanyService(final SiteConfiguration siteConf)
+ throws NamingException {
+ final String url = (String)
siteConf.getProperties().get("alfa_remote_service_url");
+ final String jndi = (String)
siteConf.getProperties().get("alfa_remote_service_jndi_name");
- /**
- * Hent ut alle produkter som er lagt inn på søkeresultatet.
- *
- */
- if (eksternt.hasListingProducts()) {
- LOG.debug("Fant listing page products, hent ut.");
- for (no.schibstedsok.alfa.external.dto.ProductResultItem
prodItem : eksternt.getListingProducts()) {
-
- final ProductResultItem item = new
ProductSearchResultItem();
+ final Properties properties = new Properties();
+ properties.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
+ properties.put("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");
+ properties.put("java.naming.provider.url", url);
- item.setFields(prodItem.getFields());
- if (prodItem.getFields().size() > 0) {
- LOG.info("Field: " + prodItem.getFields());
- internalResult.addListingResult(item);
- }
+ LOG.debug("Url: " + url + " JNDI_NAME: " + jndi);
- }
- } else {
- LOG.debug("Firmaet har ingen result page produkter.");
- }
- cat.addProducts(internalResult);
- }
- }
-}
+ final InitialContext ctx = new InitialContext(properties);
+ return (CompanyService) ctx.lookup(jndi);
+ }
+}
\ No newline at end of file
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits