ItEr56S11CUEscaladoPantallaCargaRecursosEmpresaItEr55S15: Added a new implementation of MultipleFiltersFinder to search for workers using a BandboxMultipleSearch component.

This commit is contained in:
Jacobo Aragunde Pérez 2010-04-29 11:48:39 +02:00 committed by Javier Moran Rua
parent 13c8153acd
commit 7faf495cfe
2 changed files with 110 additions and 0 deletions

View file

@ -0,0 +1,107 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.navalplanner.web.common.components.finders;
import static org.navalplanner.web.I18nHelper._;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.navalplanner.business.common.IOnTransaction;
import org.navalplanner.business.resources.daos.IWorkerDAO;
import org.navalplanner.business.resources.entities.Worker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
public class WorkerMultipleFiltersFinder extends MultipleFiltersFinder {
@Autowired
private IWorkerDAO workerDAO;
private static final List<Worker> workerList = new ArrayList<Worker>();
private IFilterEnum workerFilterEnum = new IFilterEnum() {
@Override
public String toString() {
return _("worker");
}
};
@Transactional(readOnly = true)
public void init() {
getAdHocTransactionService()
.runOnReadOnlyTransaction(new IOnTransaction<Void>() {
@Override
public Void execute() {
loadWorkers();
return null;
}
});
}
@Transactional(readOnly = true)
private void loadWorkers() {
workerList.clear();
workerList.addAll(workerDAO.getAll());
}
@Override
public List<FilterPair> getFirstTenFilters() {
Iterator<Worker> iteratorWorker = workerList.iterator();
while(iteratorWorker.hasNext() && getListMatching().size() < 10) {
Worker worker = iteratorWorker.next();
getListMatching().add(new FilterPair(
workerFilterEnum, worker.getShortDescription(), worker));
}
return getListMatching();
}
@Override
public List<FilterPair> getMatching(String filter) {
getListMatching().clear();
if ((filter != null) && (!filter.isEmpty())) {
filter = StringUtils.deleteWhitespace(filter.toLowerCase());
searchInWorkers(filter);
}
addNoneFilter();
return getListMatching();
}
private void searchInWorkers(String filter) {
boolean limited = (filter.length() < 3);
for(Worker worker : workerList) {
String name = StringUtils.deleteWhitespace(
worker.getShortDescription().toLowerCase());
if(name.contains(filter)) {
getListMatching().add(new FilterPair(
workerFilterEnum, worker.getShortDescription(), worker));
}
}
}
private void addNoneFilter() {
getListMatching().add(
new FilterPair(OrderElementFilterEnum.None,
OrderElementFilterEnum.None.toString(), null));
}
}

View file

@ -52,6 +52,9 @@
<bean id="resourcesMultipleFiltersFinder" class="org.navalplanner.web.common.components.finders.ResourcesMultipleFiltersFinder" scope="singleton"
init-method="init" />
<bean id="workerMultipleFiltersFinder" class="org.navalplanner.web.common.components.finders.WorkerMultipleFiltersFinder" scope="singleton"
init-method="init" />
<context:component-scan base-package="org.navalplanner"/>
<!-- CXF -->