1 24 package org.ofbiz.content.search; 25 26 import java.util.HashMap ; 27 import java.util.List ; 28 import java.util.Map ; 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.http.HttpServletResponse ; 31 import javax.servlet.http.HttpSession ; 32 33 import org.ofbiz.base.util.Debug; 34 import org.ofbiz.base.util.StringUtil; 35 import org.ofbiz.base.util.UtilHttp; 36 import org.ofbiz.base.util.UtilValidate; 37 import org.ofbiz.entity.GenericValue; 38 import org.ofbiz.service.GenericServiceException; 39 import org.ofbiz.service.LocalDispatcher; 40 import org.ofbiz.service.ServiceUtil; 41 42 43 44 53 public class SearchEvents { 54 55 public static final String module = SearchEvents.class.getName(); 56 57 public static String indexTree(HttpServletRequest request, HttpServletResponse response) { 58 59 Map result; 60 Map serviceInMap = new HashMap (); 61 HttpSession session = request.getSession(); 62 GenericValue userLogin = (GenericValue)session.getAttribute("userLogin"); 63 serviceInMap.put("userLogin", userLogin); 64 LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); 65 Map paramMap = UtilHttp.getParameterMap(request); 66 String siteId = (String )paramMap.get("contentId"); 67 serviceInMap.put("contentId", siteId); 68 try { 69 result = dispatcher.runSync("indexTree", serviceInMap); 70 } catch (GenericServiceException e) { 71 String errorMsg = "Error calling the indexTree service." + e.toString(); 72 Debug.logError(e, errorMsg, module); 73 request.setAttribute("_ERROR_MESSAGE_", errorMsg + e.toString()); 74 return "error"; 75 } 76 String errMsg = ServiceUtil.getErrorMessage(result); 77 if (Debug.infoOn()) Debug.logInfo("errMsg:" + errMsg, module); 78 if (Debug.infoOn()) Debug.logInfo("result:" + result, module); 79 if (UtilValidate.isEmpty(errMsg)) { 80 List badIndexList = (List )result.get("badIndexList"); 81 if (Debug.infoOn()) Debug.logInfo("badIndexList:" + badIndexList, module); 82 String badIndexMsg = StringUtil.join(badIndexList, "\n") + badIndexList.size() + " entities not indexed"; 83 Integer goodIndexCount = (Integer )result.get("goodIndexCount"); 84 String goodIndexMsg = goodIndexCount + " entities indexed."; 85 if (Debug.infoOn()) Debug.logInfo("goodIndexCount:" + goodIndexCount, module); 86 ServiceUtil.setMessages(request, badIndexMsg, goodIndexMsg, null); 87 return "success"; 88 } else { 89 ServiceUtil.setMessages(request, errMsg, null, null); 90 return "error"; 91 } 92 } 93 } 94 | Popular Tags |