All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jaeksoft.searchlib.web.ReportServlet Maven / Gradle / Ivy

Go to download

OpenSearchServer is a powerful, enterprise-class, search engine program. Using the web user interface, the crawlers (web, file, database, ...) and the REST/RESTFul API you will be able to integrate quickly and easily advanced full-text search capabilities in your application. OpenSearchServer runs on Windows and Linux/Unix/BSD.

The newest version!
/**   
 * License Agreement for OpenSearchServer
 *
 * Copyright (C) 2008-2012 Emmanuel Keller / Jaeksoft
 * 
 * http://www.open-search-server.com
 * 
 * This file is part of OpenSearchServer.
 *
 * OpenSearchServer is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 * OpenSearchServer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with OpenSearchServer. 
 *  If not, see .
 **/

package com.jaeksoft.searchlib.web;

import java.io.PrintWriter;

import com.jaeksoft.searchlib.Client;
import com.jaeksoft.searchlib.ClientCatalog;
import com.jaeksoft.searchlib.SearchLibException;
import com.jaeksoft.searchlib.config.Mailer;
import com.jaeksoft.searchlib.statistics.Aggregate;
import com.jaeksoft.searchlib.statistics.StatisticPeriodEnum;
import com.jaeksoft.searchlib.statistics.StatisticTypeEnum;
import com.jaeksoft.searchlib.statistics.StatisticsAbstract;

public class ReportServlet extends AbstractServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7243867246220284137L;

	/**
	 * 
	 */

	private void doStatistics(Client client, String stat, String period,
			PrintWriter pw) throws SearchLibException {
		if (stat == null || period == null)
			return;
		StatisticTypeEnum statType = StatisticTypeEnum.valueOf(stat
				.toUpperCase());
		StatisticPeriodEnum statPeriod = StatisticPeriodEnum.valueOf(period
				.toUpperCase());
		StatisticsAbstract statistics = client.getStatisticsList().getStat(
				statType, statPeriod);
		if (statistics == null)
			return;
		pw.println("");
		pw.println("

" + statType + " - " + statPeriod.getName() + "

"); pw.println(""); pw.println(""); for (Aggregate aggr : statistics.getArray()) { pw.println(""); pw.println(""); pw.println(""); pw.println(""); pw.println(""); pw.println(""); pw.println(""); pw.println(""); } pw.println("
Period start timeCountAverageMinMaxError
" + aggr.getStartTime() + "" + aggr.getCount() + "" + aggr.getAverage() + "" + aggr.getMin() + "" + aggr.getMax() + "" + aggr.getError() + "
"); pw.println(""); } @Override protected void doRequest(ServletTransaction transaction) throws ServletException { Mailer email = null; try { Client client = ClientCatalog.getClient(transaction .getParameterString("use")); String report = transaction.getParameterString("report"); String emails = transaction.getParameterString("emails"); if (emails == null) return; email = new Mailer(true, emails, null); if ("statistics".equals(report)) { email.setSubject("OpenSearchServer statistics report"); doStatistics(client, transaction.getParameterString("stat"), transaction.getParameterString("period"), email.getHtmlPrintWriter()); } if (email.isEmpty()) { transaction.addXmlResponse("Result", "Nothing to send"); } else { email.send(); transaction.addXmlResponse("MailSent", emails); } } catch (Exception e) { throw new ServletException(e); } finally { if (email != null) email.close(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy