KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > content > search > SearchEvents


1 /*
2  * $Id: SearchEvents.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.content.search;
25
26 import java.util.HashMap JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31 import javax.servlet.http.HttpSession JavaDoc;
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 /**
45  * SearchEvents Class
46  *
47  * @author <a HREF="mailto:byersa@automationgroups.com">Al Byers</a> Hacked from Lucene demo file
48  * @version $Rev: 5462 $
49  * @since 3.1
50  *
51  *
52  */

53 public class SearchEvents {
54
55     public static final String JavaDoc module = SearchEvents.class.getName();
56     
57     public static String JavaDoc indexTree(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
58
59         Map JavaDoc result;
60         Map JavaDoc serviceInMap = new HashMap JavaDoc();
61         HttpSession JavaDoc session = request.getSession();
62         GenericValue userLogin = (GenericValue)session.getAttribute("userLogin");
63         serviceInMap.put("userLogin", userLogin);
64         LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
65         Map JavaDoc paramMap = UtilHttp.getParameterMap(request);
66         String JavaDoc siteId = (String JavaDoc)paramMap.get("contentId");
67         serviceInMap.put("contentId", siteId);
68         try {
69             result = dispatcher.runSync("indexTree", serviceInMap);
70         } catch (GenericServiceException e) {
71             String JavaDoc 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 JavaDoc 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 JavaDoc badIndexList = (List JavaDoc)result.get("badIndexList");
81             if (Debug.infoOn()) Debug.logInfo("badIndexList:" + badIndexList, module);
82             String JavaDoc badIndexMsg = StringUtil.join(badIndexList, "\n") + badIndexList.size() + " entities not indexed";
83             Integer JavaDoc goodIndexCount = (Integer JavaDoc)result.get("goodIndexCount");
84             String JavaDoc 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