/**********************************************************************
*
* Copyright (c) by willuhn software & services
* All rights reserved
*
**********************************************************************/
package de.willuhn.jameica.hbci.search;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import de.willuhn.datasource.rmi.DBIterator;
import de.willuhn.jameica.hbci.HBCI;
import de.willuhn.jameica.hbci.Settings;
import de.willuhn.jameica.hbci.gui.action.SepaLastschriftNew;
import de.willuhn.jameica.hbci.rmi.HBCIDBService;
import de.willuhn.jameica.hbci.rmi.Konto;
import de.willuhn.jameica.hbci.rmi.SepaLastschrift;
import de.willuhn.jameica.search.Result;
import de.willuhn.jameica.search.SearchProvider;
import de.willuhn.jameica.system.Application;
import de.willuhn.logging.Logger;
import de.willuhn.util.ApplicationException;
import de.willuhn.util.I18N;
/**
* Implementierung einen Search-Provider fuer die Suche in SEPA-Lastschriften.
*/
public class SepaLastschriftSearchProvider implements SearchProvider
{
/**
* @see de.willuhn.jameica.search.SearchProvider#getName()
*/
public String getName()
{
return Application.getPluginLoader().getPlugin(HBCI.class).getResources().getI18N().tr("SEPA-Lastschriften");
}
/**
* @see de.willuhn.jameica.search.SearchProvider#search(java.lang.String)
*/
public List search(String search) throws RemoteException, ApplicationException
{
if (search == null || search.length() == 0)
return null;
String text = "%" + search.toLowerCase() + "%";
HBCIDBService service = (HBCIDBService) Settings.getDBService();
DBIterator list = service.createList(SepaLastschrift.class);
list.addFilter("LOWER(zweck) LIKE ? OR " +
"LOWER(empfaenger_name) LIKE ? OR " +
"LOWER(creditorid) LIKE ? OR " +
"LOWER(mandateid) LIKE ? OR " +
"LOWER(endtoendid) LIKE ? OR " +
"LOWER(empfaenger_konto) LIKE ?",
text,text,text,text,text,text);
list.setOrder("ORDER BY " + service.getSQLTimestamp("termin") + " DESC");
ArrayList results = new ArrayList();
while (list.hasNext())
{
results.add(new MyResult((SepaLastschrift)list.next()));
}
return results;
}
/**
* Hilfsklasse fuer die formatierte Anzeige der Ergebnisse.
*/
private class MyResult implements Result
{
private SepaLastschrift u = null;
/**
* ct.
* @param u
*/
private MyResult(SepaLastschrift u)
{
this.u = u;
}
/**
* @see de.willuhn.jameica.search.Result#execute()
*/
public void execute() throws RemoteException, ApplicationException
{
new SepaLastschriftNew().handleAction(this.u);
}
/**
* @see de.willuhn.jameica.search.Result#getName()
*/
public String getName()
{
try
{
Konto k = u.getKonto();
String[] params = new String[] {
HBCI.DATEFORMAT.format(u.getTermin()),
HBCI.DECIMALFORMAT.format(u.getBetrag()),
k.getWaehrung(),
u.getGegenkontoName(),
u.getZweck(),
k.getLongName(),
};
I18N i18n = Application.getPluginLoader().getPlugin(HBCI.class).getResources().getI18N();
return i18n.tr("{0}: {1} {2} von {3} - {4} (via {5})",params);
}
catch (RemoteException re)
{
Logger.error("unable to determin result name",re);
return null;
}
}
}
}