[Bug #1187] Fix issue filtering TaskElements by criteria in project Gantt view
FEA: ItEr75S04BugFixing
This commit is contained in:
parent
c426b8a072
commit
a9291d47b7
6 changed files with 493 additions and 6 deletions
|
|
@ -684,4 +684,14 @@ public abstract class TaskElement extends BaseEntity {
|
|||
|
||||
public abstract boolean isTask();
|
||||
|
||||
public List<TaskElement> getAllChildren() {
|
||||
List<TaskElement> children = getChildren();
|
||||
List<TaskElement> result = new ArrayList<TaskElement>();
|
||||
for (TaskElement child : children) {
|
||||
result.add(child);
|
||||
result.addAll(child.getAllChildren());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2011 Igalia, S.L.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
package org.navalplanner.web.common.components.finders;
|
||||
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
|
||||
/**
|
||||
* Different filters for {@link TaskElement}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
public enum TaskElementFilterEnum implements IFilterEnum {
|
||||
|
||||
Criterion(_("Criterion")), Label(_("Label"));
|
||||
|
||||
/**
|
||||
* Forces to mark the string as needing translation
|
||||
*/
|
||||
private static String _(String string) {
|
||||
return string;
|
||||
}
|
||||
|
||||
private String description;
|
||||
|
||||
private TaskElementFilterEnum(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,202 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2011 Igalia, S.L.
|
||||
*
|
||||
* 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 java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.navalplanner.business.hibernate.notification.PredefinedDatabaseSnapshots;
|
||||
import org.navalplanner.business.labels.entities.Label;
|
||||
import org.navalplanner.business.labels.entities.LabelType;
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.CriterionType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Implements all the methods needed to search the criteria to filter the
|
||||
* {@link TaskElement}. Provides multiples criteria to filter like
|
||||
* {@link Criterion} and {@link Label}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
public class TaskElementsMultipleFiltersFinder extends MultipleFiltersFinder {
|
||||
|
||||
@Autowired
|
||||
private PredefinedDatabaseSnapshots databaseSnapshots;
|
||||
|
||||
protected TaskElementsMultipleFiltersFinder() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FilterPair> getFirstTenFilters() {
|
||||
getListMatching().clear();
|
||||
fillWithFirstTenFiltersLabels();
|
||||
fillWithFirstTenFiltersCriterions();
|
||||
addNoneFilter();
|
||||
return getListMatching();
|
||||
}
|
||||
|
||||
private List<FilterPair> fillWithFirstTenFiltersLabels() {
|
||||
Map<LabelType, List<Label>> mapLabels = getLabelsMap();
|
||||
Iterator<LabelType> iteratorLabelType = mapLabels.keySet().iterator();
|
||||
while (iteratorLabelType.hasNext() && getListMatching().size() < 10) {
|
||||
LabelType type = iteratorLabelType.next();
|
||||
for (int i = 0; getListMatching().size() < 10
|
||||
&& i < mapLabels.get(type).size(); i++) {
|
||||
Label label = mapLabels.get(type).get(i);
|
||||
addLabel(type, label);
|
||||
}
|
||||
}
|
||||
return getListMatching();
|
||||
}
|
||||
|
||||
private Map<LabelType, List<Label>> getLabelsMap() {
|
||||
return databaseSnapshots.snapshotLabelsMap();
|
||||
}
|
||||
|
||||
private List<FilterPair> fillWithFirstTenFiltersCriterions() {
|
||||
SortedMap<CriterionType, List<Criterion>> mapCriterions = getMapCriterions();
|
||||
Iterator<CriterionType> iteratorCriterionType = mapCriterions.keySet()
|
||||
.iterator();
|
||||
while (iteratorCriterionType.hasNext() && getListMatching().size() < 10) {
|
||||
CriterionType type = iteratorCriterionType.next();
|
||||
for (int i = 0; getListMatching().size() < 10
|
||||
&& i < mapCriterions.get(type).size(); i++) {
|
||||
Criterion criterion = mapCriterions.get(type).get(i);
|
||||
addCriterion(type, criterion);
|
||||
}
|
||||
}
|
||||
return getListMatching();
|
||||
}
|
||||
|
||||
private SortedMap<CriterionType, List<Criterion>> getMapCriterions() {
|
||||
return databaseSnapshots.snapshotCriterionsMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FilterPair> getMatching(String filter) {
|
||||
getListMatching().clear();
|
||||
if ((filter != null) && (!filter.isEmpty())) {
|
||||
filter = StringUtils.deleteWhitespace(filter.toLowerCase());
|
||||
searchInCriterionTypes(filter);
|
||||
searchInLabelTypes(filter);
|
||||
}
|
||||
|
||||
addNoneFilter();
|
||||
return getListMatching();
|
||||
}
|
||||
|
||||
private void searchInCriterionTypes(String filter) {
|
||||
boolean limited = (filter.length() < 3);
|
||||
for (CriterionType type : getMapCriterions().keySet()) {
|
||||
String name = StringUtils.deleteWhitespace(type.getName()
|
||||
.toLowerCase());
|
||||
if (name.contains(filter)) {
|
||||
setFilterPairCriterionType(type, limited);
|
||||
} else {
|
||||
searchInCriterions(type, filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void searchInCriterions(CriterionType type, String filter) {
|
||||
List<Criterion> list = getMapCriterions().get(type);
|
||||
if (list == null) {
|
||||
return;
|
||||
}
|
||||
for (Criterion criterion : list) {
|
||||
String name = StringUtils.deleteWhitespace(criterion.getName()
|
||||
.toLowerCase());
|
||||
if (name.contains(filter)) {
|
||||
addCriterion(type, criterion);
|
||||
if ((filter.length() < 3) && (getListMatching().size() > 9)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setFilterPairCriterionType(CriterionType type, boolean limited) {
|
||||
List<Criterion> list = getMapCriterions().get(type);
|
||||
if (list == null) {
|
||||
return;
|
||||
}
|
||||
for (Criterion criterion : list) {
|
||||
addCriterion(type, criterion);
|
||||
if ((limited) && (getListMatching().size() > 9)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void searchInLabelTypes(String filter) {
|
||||
boolean limited = (filter.length() < 3);
|
||||
for (LabelType type : getLabelsMap().keySet()) {
|
||||
String name = StringUtils.deleteWhitespace(type.getName()
|
||||
.toLowerCase());
|
||||
if (name.contains(filter)) {
|
||||
setFilterPairLabelType(type, limited);
|
||||
} else {
|
||||
searchInLabels(type, filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void searchInLabels(LabelType type, String filter) {
|
||||
for (Label label : getLabelsMap().get(type)) {
|
||||
String name = StringUtils.deleteWhitespace(label.getName()
|
||||
.toLowerCase());
|
||||
if (name.contains(filter)) {
|
||||
addLabel(type, label);
|
||||
if ((filter.length() < 3) && (getListMatching().size() > 9)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setFilterPairLabelType(LabelType type, boolean limited) {
|
||||
for (Label label : getLabelsMap().get(type)) {
|
||||
addLabel(type, label);
|
||||
if ((limited) && (getListMatching().size() > 9)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addCriterion(CriterionType type, Criterion criterion) {
|
||||
String pattern = criterion.getName() + " ( " + type.getName() + " )";
|
||||
getListMatching().add(
|
||||
new FilterPair(TaskElementFilterEnum.Criterion, type
|
||||
.getResource().toLowerCase(), pattern, criterion));
|
||||
}
|
||||
|
||||
private void addLabel(LabelType type, Label label) {
|
||||
String pattern = label.getName() + " ( " + type.getName() + " )";
|
||||
getListMatching().add(
|
||||
new FilterPair(TaskElementFilterEnum.Label, pattern, label));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,219 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2011 Igalia, S.L.
|
||||
*
|
||||
* 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.orders;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.navalplanner.business.labels.entities.Label;
|
||||
import org.navalplanner.business.planner.entities.GenericResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.ResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.web.common.components.finders.FilterPair;
|
||||
import org.navalplanner.web.common.components.finders.TaskElementFilterEnum;
|
||||
import org.zkoss.ganttz.IPredicate;
|
||||
|
||||
/**
|
||||
* Checks if {@link TaskElement} matches with the different filters.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
public class TaskElementPredicate implements IPredicate {
|
||||
|
||||
private List<FilterPair> filters;
|
||||
|
||||
private Date startDate;
|
||||
|
||||
private Date finishDate;
|
||||
|
||||
private String name;
|
||||
|
||||
private boolean ignoreLabelsInheritance;
|
||||
|
||||
public TaskElementPredicate(List<FilterPair> filters, Date startDate,
|
||||
Date finishDate, String name, boolean ignoreLabelsInheritance) {
|
||||
this.filters = filters;
|
||||
this.startDate = startDate;
|
||||
this.finishDate = finishDate;
|
||||
this.name = name;
|
||||
this.ignoreLabelsInheritance = ignoreLabelsInheritance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(Object object) {
|
||||
final TaskElement taskElement = (TaskElement) object;
|
||||
return accepts(taskElement) || accepts(taskElement.getAllChildren());
|
||||
}
|
||||
|
||||
private boolean accepts(TaskElement taskElement) {
|
||||
if (taskElement == null) {
|
||||
return false;
|
||||
}
|
||||
if (acceptFilters(taskElement) && acceptFiltersDates(taskElement)
|
||||
&& acceptFilterName(taskElement)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean accepts(List<TaskElement> taskElements) {
|
||||
for (TaskElement taskElement : taskElements) {
|
||||
if (accepts(taskElement)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean acceptFilters(TaskElement taskElement) {
|
||||
if ((filters == null) || (filters.isEmpty())) {
|
||||
return true;
|
||||
}
|
||||
for (FilterPair filter : filters) {
|
||||
if (!acceptFilter(filter, taskElement)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean acceptFilter(FilterPair filter, TaskElement taskElement) {
|
||||
switch ((TaskElementFilterEnum) filter.getType()) {
|
||||
case Criterion:
|
||||
return acceptCriterion(filter, taskElement);
|
||||
case Label:
|
||||
return acceptLabel(filter, taskElement);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean acceptCriterion(FilterPair filter, TaskElement taskElement) {
|
||||
Criterion filterCriterion = (Criterion) filter.getValue();
|
||||
return existCriterionInTaskElementResourceAllocations(filterCriterion,
|
||||
taskElement);
|
||||
}
|
||||
|
||||
private boolean existCriterionInTaskElementResourceAllocations(
|
||||
Criterion filterCriterion, TaskElement taskElement) {
|
||||
for (ResourceAllocation<?> each : taskElement
|
||||
.getAllResourceAllocations()) {
|
||||
if (acceptsCriterionInResourceAllocation(filterCriterion, each)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean acceptsCriterionInResourceAllocation(
|
||||
Criterion filterCriterion, ResourceAllocation<?> resourceAllocation) {
|
||||
if (resourceAllocation instanceof GenericResourceAllocation) {
|
||||
Set<Criterion> criteria = ((GenericResourceAllocation) resourceAllocation)
|
||||
.getCriterions();
|
||||
for (Criterion criterion : criteria) {
|
||||
if (criterion.getId().equals(filterCriterion.getId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean acceptLabel(FilterPair filter, TaskElement taskElement) {
|
||||
Label filterLabel = (Label) filter.getValue();
|
||||
return existLabelInTaskElement(filterLabel, taskElement);
|
||||
}
|
||||
|
||||
private boolean existLabelInTaskElement(Label filterLabel,
|
||||
TaskElement taskElement) {
|
||||
Set<Label> labels;
|
||||
if (ignoreLabelsInheritance) {
|
||||
labels = taskElement.getOrderElement().getLabels();
|
||||
} else {
|
||||
labels = taskElement.getOrderElement().getAllLabels();
|
||||
}
|
||||
for (Label label : labels) {
|
||||
if (label.getId().equals(filterLabel.getId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean acceptFiltersDates(TaskElement taskElement) {
|
||||
return (acceptStartDate(taskElement.getStartDate()) && (acceptFinishDate(taskElement
|
||||
.getEndDate())));
|
||||
}
|
||||
|
||||
private boolean acceptStartDate(Date initDate) {
|
||||
if ((initDate == null) && (startDate == null)) {
|
||||
return true;
|
||||
}
|
||||
return isInTheRangeFilterDates(initDate);
|
||||
}
|
||||
|
||||
private boolean acceptFinishDate(Date deadLine) {
|
||||
if ((deadLine == null) && (finishDate == null)) {
|
||||
return true;
|
||||
}
|
||||
return isInTheRangeFilterDates(deadLine);
|
||||
}
|
||||
|
||||
private boolean isInTheRangeFilterDates(Date date) {
|
||||
// Check if date is into interval between the startdate and finish date
|
||||
return (isGreaterToStartDate(date, startDate) && isLowerToFinishDate(
|
||||
date, finishDate));
|
||||
}
|
||||
|
||||
private boolean isGreaterToStartDate(Date date, Date startDate) {
|
||||
if (startDate == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (date != null && (date.compareTo(startDate) >= 0)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isLowerToFinishDate(Date date, Date finishDate) {
|
||||
if (finishDate == null) {
|
||||
return true;
|
||||
}
|
||||
if (date != null && (date.compareTo(finishDate) <= 0)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean acceptFilterName(TaskElement taskElement) {
|
||||
if (name == null) {
|
||||
return true;
|
||||
}
|
||||
if ((taskElement.getName() != null)
|
||||
&& (StringUtils.containsIgnoreCase(taskElement.getName(), name))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ import org.navalplanner.web.common.ViewSwitcher;
|
|||
import org.navalplanner.web.common.components.bandboxsearch.BandboxMultipleSearch;
|
||||
import org.navalplanner.web.common.components.finders.FilterPair;
|
||||
import org.navalplanner.web.orders.OrderCRUDController;
|
||||
import org.navalplanner.web.orders.OrderElementPredicate;
|
||||
import org.navalplanner.web.orders.TaskElementPredicate;
|
||||
import org.navalplanner.web.planner.advances.AdvanceAssignmentPlanningController;
|
||||
import org.navalplanner.web.planner.calendar.CalendarAllocationController;
|
||||
import org.navalplanner.web.planner.consolidations.AdvanceConsolidationController;
|
||||
|
|
@ -195,6 +195,7 @@ public class OrderPlanningController implements Composer {
|
|||
.getFellow("labelsWithoutInheritance");
|
||||
bdFiltersOrderElement = (BandboxMultipleSearch) filterComponent
|
||||
.getFellow("bdFiltersOrderElement");
|
||||
bdFiltersOrderElement.setFinder("taskElementsMultipleFiltersFinder");
|
||||
filterNameOrderElement = (Textbox) filterComponent
|
||||
.getFellow("filterNameOrderElement");
|
||||
filterComponent.setVisible(true);
|
||||
|
|
@ -240,7 +241,7 @@ public class OrderPlanningController implements Composer {
|
|||
filterByPredicate(createPredicate());
|
||||
}
|
||||
|
||||
private OrderElementPredicate createPredicate() {
|
||||
private TaskElementPredicate createPredicate() {
|
||||
List<FilterPair> listFilters = (List<FilterPair>) bdFiltersOrderElement
|
||||
.getSelectedElements();
|
||||
Date startDate = filterStartDateOrderElement.getValue();
|
||||
|
|
@ -253,7 +254,7 @@ public class OrderPlanningController implements Composer {
|
|||
return null;
|
||||
}
|
||||
|
||||
return new OrderElementPredicate(listFilters, startDate, finishDate,
|
||||
return new TaskElementPredicate(listFilters, startDate, finishDate,
|
||||
name, ignoreLabelsInheritance);
|
||||
}
|
||||
|
||||
|
|
@ -265,11 +266,12 @@ public class OrderPlanningController implements Composer {
|
|||
this.labelsWithoutInheritance = labelsWithoutInheritance;
|
||||
}
|
||||
|
||||
private void filterByPredicate(final OrderElementPredicate predicate) {
|
||||
private void filterByPredicate(final TaskElementPredicate predicate) {
|
||||
LongOperationFeedback.execute(orderElementFilter, new ILongOperation() {
|
||||
|
||||
@Override
|
||||
public void doAction() {
|
||||
// FIXME remove or change
|
||||
model.forceLoadLabelsAndCriterionRequirements();
|
||||
|
||||
final IContext<?> context = planner.getContext();
|
||||
|
|
@ -284,8 +286,7 @@ public class OrderPlanningController implements Composer {
|
|||
.getMapper()
|
||||
.findAssociatedDomainObject(task);
|
||||
return taskElement.isMilestone()
|
||||
|| predicate.accepts(taskElement
|
||||
.getOrderElement());
|
||||
|| predicate.accepts(taskElement);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@
|
|||
|
||||
<bean id="orderElementsMultipleFiltersFinder" class="org.navalplanner.web.common.components.finders.OrderElementsMultipleFiltersFinder" scope="singleton"/>
|
||||
|
||||
<bean id="taskElementsMultipleFiltersFinder" class="org.navalplanner.web.common.components.finders.TaskElementsMultipleFiltersFinder" scope="singleton" />
|
||||
|
||||
<bean id="resourcesMultipleFiltersFinder" class="org.navalplanner.web.common.components.finders.ResourcesMultipleFiltersFinder" scope="singleton" />
|
||||
|
||||
<bean id="limitingResourceAllocationMultipleFiltersFinder" class="org.navalplanner.web.common.components.finders.LimitingResourceAllocationMultipleFiltersFinder" scope="singleton"/>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue