Use new database query when filtering projects list
The database query that filters the orders by several fields is used only when the subelements checkbox is not clicked. Otherwise the old query is used and the old behavior is kept for the filtering. However, if the checkbox is not clicked, the new query is used to get the initial list and to do the successive filtering too. NOTE: Resources are never assigned directly to the root element, so if you filter by resources it'll only work if you have the subelements checkbox clicked. FEA: ItEr77S15FilteringEnhancements
This commit is contained in:
parent
2da6a83a61
commit
eb3871d234
4 changed files with 103 additions and 20 deletions
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.libreplan.web.planner;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
|
@ -282,4 +283,23 @@ public class TaskGroupPredicate implements IPredicate {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean isIncludeChildren() {
|
||||
return includeChildren;
|
||||
}
|
||||
|
||||
public List<FilterPair> getFilters() {
|
||||
if (filters == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.unmodifiableList(filters);
|
||||
}
|
||||
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public Date getFinishDate() {
|
||||
return finishDate;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -39,8 +39,6 @@ import org.libreplan.business.users.entities.User;
|
|||
import org.libreplan.business.users.entities.UserRole;
|
||||
import org.libreplan.web.common.components.bandboxsearch.BandboxMultipleSearch;
|
||||
import org.libreplan.web.common.components.finders.FilterPair;
|
||||
import org.libreplan.web.common.components.finders.IFilterEnum;
|
||||
import org.libreplan.web.common.components.finders.OrderFilterEnum;
|
||||
import org.libreplan.web.common.components.finders.TaskGroupFilterEnum;
|
||||
import org.libreplan.web.planner.TaskGroupPredicate;
|
||||
import org.libreplan.web.planner.tabs.MultipleTabsPlannerController;
|
||||
|
|
@ -48,7 +46,6 @@ import org.libreplan.web.security.SecurityUtils;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.zkoss.ganttz.IPredicate;
|
||||
import org.zkoss.ganttz.Planner;
|
||||
import org.zkoss.ganttz.extensions.ICommandOnTask;
|
||||
import org.zkoss.ganttz.timetracker.zoom.ZoomLevel;
|
||||
|
|
@ -350,7 +347,7 @@ public class CompanyPlanningController implements Composer {
|
|||
filterByPredicate(createPredicate());
|
||||
}
|
||||
|
||||
private IPredicate createPredicate() {
|
||||
private TaskGroupPredicate createPredicate() {
|
||||
List<FilterPair> listFilters = (List<FilterPair>) bdFilters
|
||||
.getSelectedElements();
|
||||
Date startDate = filterStartDate.getValue();
|
||||
|
|
@ -358,7 +355,8 @@ public class CompanyPlanningController implements Composer {
|
|||
Boolean includeOrderElements = checkIncludeOrderElements.isChecked();
|
||||
|
||||
if (listFilters.isEmpty() && startDate == null && finishDate == null) {
|
||||
IPredicate predicate = model.getDefaultPredicate(includeOrderElements);
|
||||
TaskGroupPredicate predicate = model
|
||||
.getDefaultPredicate(includeOrderElements);
|
||||
//show filter dates calculated by default on screen
|
||||
if(model.getFilterStartDate() != null) {
|
||||
filterStartDate.setValue(model.getFilterStartDate());
|
||||
|
|
@ -373,7 +371,7 @@ public class CompanyPlanningController implements Composer {
|
|||
includeOrderElements);
|
||||
}
|
||||
|
||||
private void filterByPredicate(IPredicate predicate) {
|
||||
private void filterByPredicate(TaskGroupPredicate predicate) {
|
||||
// Recalculate predicate
|
||||
model.setConfigurationToPlanner(planner, additional,
|
||||
doubleClickCommand, predicate);
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import org.libreplan.business.common.IOnTransaction;
|
|||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||
import org.libreplan.business.common.entities.ProgressType;
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.externalcompanies.entities.ExternalCompany;
|
||||
import org.libreplan.business.hibernate.notification.PredefinedDatabaseSnapshots;
|
||||
import org.libreplan.business.orders.daos.IOrderDAO;
|
||||
import org.libreplan.business.orders.entities.Order;
|
||||
|
|
@ -57,10 +58,13 @@ import org.libreplan.business.planner.entities.ICompanyEarnedValueCalculator;
|
|||
import org.libreplan.business.planner.entities.TaskElement;
|
||||
import org.libreplan.business.planner.entities.TaskGroup;
|
||||
import org.libreplan.business.planner.entities.TaskMilestone;
|
||||
import org.libreplan.business.resources.entities.Criterion;
|
||||
import org.libreplan.business.scenarios.IScenarioManager;
|
||||
import org.libreplan.business.scenarios.entities.Scenario;
|
||||
import org.libreplan.business.users.daos.IUserDAO;
|
||||
import org.libreplan.business.users.entities.User;
|
||||
import org.libreplan.web.common.components.finders.FilterPair;
|
||||
import org.libreplan.web.common.components.finders.TaskGroupFilterEnum;
|
||||
import org.libreplan.web.planner.TaskElementAdapter;
|
||||
import org.libreplan.web.planner.TaskGroupPredicate;
|
||||
import org.libreplan.web.planner.chart.Chart;
|
||||
|
|
@ -81,7 +85,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.zkforge.timeplot.Plotinfo;
|
||||
import org.zkforge.timeplot.Timeplot;
|
||||
import org.zkoss.ganttz.IChartVisibilityChangedListener;
|
||||
import org.zkoss.ganttz.IPredicate;
|
||||
import org.zkoss.ganttz.Planner;
|
||||
import org.zkoss.ganttz.adapters.IStructureNavigator;
|
||||
import org.zkoss.ganttz.adapters.PlannerConfiguration;
|
||||
|
|
@ -200,7 +203,7 @@ public class CompanyPlanningModel implements ICompanyPlanningModel {
|
|||
public void setConfigurationToPlanner(final Planner planner,
|
||||
Collection<ICommandOnTask<TaskElement>> additional,
|
||||
ICommandOnTask<TaskElement> doubleClickCommand,
|
||||
IPredicate predicate) {
|
||||
TaskGroupPredicate predicate) {
|
||||
currentScenario = scenarioManager.getCurrent();
|
||||
final PlannerConfiguration<TaskElement> configuration = createConfiguration(predicate);
|
||||
|
||||
|
|
@ -694,24 +697,36 @@ public class CompanyPlanningModel implements ICompanyPlanningModel {
|
|||
}
|
||||
|
||||
private PlannerConfiguration<TaskElement> createConfiguration(
|
||||
IPredicate predicate) {
|
||||
TaskGroupPredicate predicate) {
|
||||
return new PlannerConfiguration<TaskElement>(
|
||||
taskElementAdapterCreator.createForCompany(currentScenario),
|
||||
new TaskElementNavigator(), retainOnlyTopLevel(predicate));
|
||||
}
|
||||
|
||||
private List<TaskElement> retainOnlyTopLevel(IPredicate predicate) {
|
||||
private List<TaskElement> retainOnlyTopLevel(TaskGroupPredicate predicate) {
|
||||
List<TaskElement> result = new ArrayList<TaskElement>();
|
||||
|
||||
List<Order> list = orderDAO.getOrdersByReadAuthorizationByScenario(
|
||||
SecurityUtils.getSessionUserLoginName(), currentScenario);
|
||||
List<Order> list = getOrders(predicate);
|
||||
for (Order order : list) {
|
||||
order.useSchedulingDataFor(currentScenario, false);
|
||||
TaskGroup associatedTaskElement = order.getAssociatedTaskElement();
|
||||
|
||||
if (associatedTaskElement != null
|
||||
&& (predicate == null || predicate
|
||||
.accepts(associatedTaskElement))) {
|
||||
if (associatedTaskElement != null) {
|
||||
if (predicate != null) {
|
||||
// If predicate includeChildren then we check if it accepts
|
||||
// the element
|
||||
if (predicate.isIncludeChildren()
|
||||
&& !predicate.accepts(associatedTaskElement)) {
|
||||
// If it doesn't accept the element we move on to the
|
||||
// next order
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// If predicate doesn't includeChildren then the orders where
|
||||
// already filtered in the DB query.
|
||||
// Otherwise they've been filtered with the predicate above, and
|
||||
// if they didn't pass the filter the execution doesn't reach
|
||||
// this point.
|
||||
associatedTaskElement.setSimplifiedAssignedStatusCalculationEnabled(true);
|
||||
result.add(associatedTaskElement);
|
||||
}
|
||||
|
|
@ -725,9 +740,59 @@ public class CompanyPlanningModel implements ICompanyPlanningModel {
|
|||
return result;
|
||||
}
|
||||
|
||||
private List<Order> getOrders(TaskGroupPredicate predicate) {
|
||||
String username = SecurityUtils.getSessionUserLoginName();
|
||||
if (predicate.isIncludeChildren()) {
|
||||
return orderDAO.getOrdersByReadAuthorizationByScenario(username,
|
||||
currentScenario);
|
||||
}
|
||||
|
||||
Date startDate = predicate.getStartDate();
|
||||
Date endDate = predicate.getFinishDate();
|
||||
List<org.libreplan.business.labels.entities.Label> labels = new ArrayList<org.libreplan.business.labels.entities.Label>();
|
||||
List<Criterion> criteria = new ArrayList<Criterion>();
|
||||
ExternalCompany customer = null;
|
||||
OrderStatusEnum state = null;
|
||||
|
||||
for (FilterPair filterPair : (List<FilterPair>) predicate.getFilters()) {
|
||||
TaskGroupFilterEnum type = (TaskGroupFilterEnum) filterPair
|
||||
.getType();
|
||||
switch (type) {
|
||||
case Label:
|
||||
labels.add((org.libreplan.business.labels.entities.Label) filterPair
|
||||
.getValue());
|
||||
break;
|
||||
case Criterion:
|
||||
criteria.add((Criterion) filterPair.getValue());
|
||||
break;
|
||||
case ExternalCompany:
|
||||
if (customer != null) {
|
||||
// It's impossible to have an Order associated to more than
|
||||
// 1 customer
|
||||
return Collections.emptyList();
|
||||
}
|
||||
customer = (ExternalCompany) filterPair.getValue();
|
||||
break;
|
||||
case State:
|
||||
if (state != null) {
|
||||
// It's impossible to have an Order associated with more
|
||||
// than 1 state
|
||||
return Collections.emptyList();
|
||||
}
|
||||
state = (OrderStatusEnum) filterPair.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return orderDAO
|
||||
.getOrdersByReadAuthorizationBetweenDatesByLabelsCriteriaCustomerAndState(
|
||||
username, currentScenario, startDate, endDate, labels,
|
||||
criteria, customer, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public IPredicate getDefaultPredicate(Boolean includeOrderElements) {
|
||||
public TaskGroupPredicate getDefaultPredicate(Boolean includeOrderElements) {
|
||||
|
||||
Date startDate = (Date) Sessions.getCurrent().getAttribute(
|
||||
"companyFilterStartDate");
|
||||
|
|
|
|||
|
|
@ -27,9 +27,8 @@ import java.util.Date;
|
|||
import org.joda.time.LocalDate;
|
||||
import org.libreplan.business.common.entities.ProgressType;
|
||||
import org.libreplan.business.planner.entities.TaskElement;
|
||||
import org.libreplan.business.templates.entities.OrderTemplate;
|
||||
import org.libreplan.web.planner.TaskGroupPredicate;
|
||||
import org.libreplan.web.planner.tabs.MultipleTabsPlannerController;
|
||||
import org.zkoss.ganttz.IPredicate;
|
||||
import org.zkoss.ganttz.Planner;
|
||||
import org.zkoss.ganttz.extensions.ICommandOnTask;
|
||||
|
||||
|
|
@ -42,7 +41,8 @@ public interface ICompanyPlanningModel {
|
|||
|
||||
public void setConfigurationToPlanner(Planner planner,
|
||||
Collection<ICommandOnTask<TaskElement>> additional,
|
||||
ICommandOnTask<TaskElement> doubleClickCommand, IPredicate predicate);
|
||||
ICommandOnTask<TaskElement> doubleClickCommand,
|
||||
TaskGroupPredicate predicate);
|
||||
|
||||
public void setTabsController(MultipleTabsPlannerController tabsController);
|
||||
|
||||
|
|
@ -52,6 +52,6 @@ public interface ICompanyPlanningModel {
|
|||
|
||||
ProgressType getProgressTypeFromConfiguration();
|
||||
|
||||
public IPredicate getDefaultPredicate(Boolean includeOrderElements);
|
||||
public TaskGroupPredicate getDefaultPredicate(Boolean includeOrderElements);
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue