
com.jaeksoft.searchlib.web.ReportServlet Maven / Gradle / Ivy
/**
* 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("Period start time Count Average Min Max Error ");
for (Aggregate aggr : statistics.getArray()) {
pw.println("");
pw.println("" + aggr.getStartTime() + " ");
pw.println("" + aggr.getCount() + " ");
pw.println("" + aggr.getAverage() + " ");
pw.println("" + aggr.getMin() + " ");
pw.println("" + aggr.getMax() + " ");
pw.println("" + aggr.getError() + " ");
pw.println(" ");
}
pw.println("
");
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 - 2025 Weber Informatics LLC | Privacy Policy