diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/components/finders/OrderElementFilterEnum.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/components/finders/OrderElementFilterEnum.java new file mode 100644 index 000000000..a10bd100b --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/components/finders/OrderElementFilterEnum.java @@ -0,0 +1,49 @@ +/* + * 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 . + */ + +/** + * @author Susana Montes Pedreira + */ +package org.navalplanner.web.common.components.finders; + +import static org.navalplanner.web.I18nHelper._; + +import org.navalplanner.business.orders.entities.OrderElement; + +/** + * Different filters for {@link OrderElement}. + * + * @author Manuel Rego Casasnovas + */ +public enum OrderElementFilterEnum implements IFilterEnum { + + None("..."), Criterion(_("Criterion")), Label(_("Label")); + + private String description; + + private OrderElementFilterEnum(String description) { + this.description = description; + } + + public String toString() { + return this.description; + } + +} diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/components/finders/OrderElementsMultipleFiltersFinder.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/components/finders/OrderElementsMultipleFiltersFinder.java new file mode 100644 index 000000000..5d110d12c --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/components/finders/OrderElementsMultipleFiltersFinder.java @@ -0,0 +1,244 @@ +/* + * 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 . + */ + +package org.navalplanner.web.common.components.finders; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.navalplanner.business.common.IOnTransaction; +import org.navalplanner.business.labels.daos.ILabelDAO; +import org.navalplanner.business.labels.daos.ILabelTypeDAO; +import org.navalplanner.business.labels.entities.Label; +import org.navalplanner.business.labels.entities.LabelType; +import org.navalplanner.business.orders.entities.OrderStatusEnum; +import org.navalplanner.business.resources.daos.ICriterionDAO; +import org.navalplanner.business.resources.daos.ICriterionTypeDAO; +import org.navalplanner.business.resources.entities.Criterion; +import org.navalplanner.business.resources.entities.CriterionType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +/** + * Implements all the methods needed to search the criterion to filter the + * orders. Provides multiples criterions to filter like {@link Criterion} and + * {@link Label}. + * + * @author Manuel Rego Casasnovas + */ +public class OrderElementsMultipleFiltersFinder extends MultipleFiltersFinder { + + @Autowired + private ICriterionTypeDAO criterionTypeDAO; + + @Autowired + private ILabelTypeDAO labelTypeDAO; + + @Autowired + private ICriterionDAO criterionDAO; + + @Autowired + private ILabelDAO labelDAO; + + private static final Map> mapCriterions = new HashMap>(); + + private static final Map> mapLabels = new HashMap>(); + + private static OrderStatusEnum[] ordersStatusEnums; + + protected OrderElementsMultipleFiltersFinder() { + + } + + @Transactional(readOnly = true) + public void init() { + getAdHocTransactionService() + .runOnReadOnlyTransaction(new IOnTransaction() { + @Override + public Void execute() { + loadLabels(); + loadCriterions(); + return null; + } + }); + } + + private void loadCriterions() { + mapCriterions.clear(); + List criterionTypes = criterionTypeDAO + .getCriterionTypes(); + for (CriterionType criterionType : criterionTypes) { + List criterions = new ArrayList(criterionDAO + .findByType(criterionType)); + + mapCriterions.put(criterionType, criterions); + } + } + + private void loadLabels() { + mapLabels.clear(); + List labelTypes = labelTypeDAO.getAll(); + for (LabelType labelType : labelTypes) { + List