Implement first version of project status report

* Using a DTO to manage the information in the report (ProjectStatusReportDTO)
* Add filter by projects in the UI

FEA: ItEr77S09WBSReport
This commit is contained in:
Manuel Rego Casasnovas 2012-09-11 13:25:06 +02:00
parent 17dcfc1f84
commit dee3588280
5 changed files with 285 additions and 6 deletions

View file

@ -0,0 +1,90 @@
/*
* This file is part of LibrePlan
*
* Copyright (C) 2012 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.libreplan.business.reports.dtos;
import org.libreplan.business.orders.entities.OrderElement;
import org.libreplan.business.orders.entities.SumChargedEffort;
import org.libreplan.business.orders.entities.TaskSource;
import org.libreplan.business.workingday.EffortDuration;
/**
* DTO to represent each row in the Project Status report.
*
* @author Manuel Rego Casasnovas <rego@igalia.com>
*/
public class ProjectStatusReportDTO {
private String code;
private String name;
private EffortDuration estimatedHours;
private EffortDuration plannedHours;
private EffortDuration imputedHours;
public ProjectStatusReportDTO(OrderElement orderElement) {
code = orderElement.getCode();
name = orderElement.getName();
Integer estimatedHours = orderElement.getWorkHours();
this.estimatedHours = estimatedHours != null ? EffortDuration
.hours(estimatedHours) : null;
TaskSource taskSource = orderElement.getTaskSource();
if (taskSource != null) {
plannedHours = taskSource.getTask().getSumOfAssignedEffort();
}
SumChargedEffort sumChargedEffort = orderElement.getSumChargedEffort();
if (sumChargedEffort != null) {
imputedHours = sumChargedEffort.getTotalChargedEffort();
}
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
public String getEstimatedHours() {
return toString(estimatedHours);
}
public String getPlannedHours() {
return toString(plannedHours);
}
public String getImputedHours() {
return toString(imputedHours);
}
private String toString(EffortDuration effortDuration) {
if (effortDuration == null) {
return null;
}
return effortDuration.toFormattedString();
}
}

View file

@ -0,0 +1,38 @@
/*
* This file is part of LibrePlan
*
* Copyright (C) 2012 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.libreplan.web.reports;
import java.util.List;
import org.libreplan.business.orders.entities.Order;
import org.libreplan.business.reports.dtos.ProjectStatusReportDTO;
/**
* Contract for Project Status report model.
*
* @author Manuel Rego Casasnovas <rego@igalia.com>
*/
public interface IProjectStatusReportModel {
List<Order> getOrders();
List<ProjectStatusReportDTO> getProjectStatusReportDTOs(Order order);
}

View file

@ -19,10 +19,22 @@
package org.libreplan.web.reports;
import static org.libreplan.web.I18nHelper._;
import java.util.List;
import java.util.Map;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import org.libreplan.business.orders.entities.Order;
import org.libreplan.business.reports.dtos.ProjectStatusReportDTO;
import org.libreplan.web.common.components.bandboxsearch.BandboxSearch;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import com.igalia.java.zk.components.JasperreportComponent;
/**
* Controller for UI operations of Project Satus report.
@ -34,6 +46,10 @@ public class ProjectStatusReportController extends LibrePlanReportController {
private static final String REPORT_NAME = "projectStatusReport";
private IProjectStatusReportModel projectStatusReportModel;
private BandboxSearch bandboxSelectOrder;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
@ -47,7 +63,39 @@ public class ProjectStatusReportController extends LibrePlanReportController {
@Override
protected JRDataSource getDataSource() {
return new JREmptyDataSource();
List<ProjectStatusReportDTO> dtos = projectStatusReportModel
.getProjectStatusReportDTOs(getSelectedOrder());
if (dtos.isEmpty()) {
return new JREmptyDataSource();
}
return new JRBeanCollectionDataSource(dtos);
}
@Override
public void showReport(JasperreportComponent jasperreport) {
final Order order = getSelectedOrder();
if (order == null) {
throw new WrongValueException(bandboxSelectOrder,
_("Please, select a project"));
}
super.showReport(jasperreport);
}
private Order getSelectedOrder() {
return (Order) bandboxSelectOrder.getSelectedElement();
}
public List<Order> getOrders() {
return projectStatusReportModel.getOrders();
}
@Override
protected Map<String, Object> getParameters() {
Map<String, Object> result = super.getParameters();
Order order = getSelectedOrder();
result.put("project", order.getName() + " (" + order.getCode() + ")");
return result;
}
}

View file

@ -0,0 +1,81 @@
/*
* This file is part of LibrePlan
*
* Copyright (C) 2012 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.libreplan.web.reports;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.libreplan.business.orders.daos.IOrderDAO;
import org.libreplan.business.orders.entities.Order;
import org.libreplan.business.orders.entities.OrderElement;
import org.libreplan.business.reports.dtos.ProjectStatusReportDTO;
import org.libreplan.business.scenarios.IScenarioManager;
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.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* Model for Project Status report.
*
* @author Manuel Rego Casasnovas <rego@igalia.com>
*/
@Service
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class ProjectStatusReportModel implements IProjectStatusReportModel {
@Autowired
private IOrderDAO orderDAO;
@Autowired
private IScenarioManager scenarioManager;
@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public List<Order> getOrders() {
List<Order> result = orderDAO.getOrdersByReadAuthorizationByScenario(
SecurityUtils.getSessionUserLoginName(),
scenarioManager.getCurrent());
Collections.sort(result);
return result;
}
@Override
@Transactional(readOnly = true)
public List<ProjectStatusReportDTO> getProjectStatusReportDTOs(Order order) {
orderDAO.reattach(order);
order.useSchedulingDataFor(scenarioManager.getCurrent());
List<ProjectStatusReportDTO> dtos = new ArrayList<ProjectStatusReportDTO>();
for (OrderElement child : order.getAllChildren()) {
dtos.add(new ProjectStatusReportDTO(child));
}
return dtos;
}
}

View file

@ -17,7 +17,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<?page title="${i18n:_('LibrePlan: Budget Report')}" id="reports"?>
<?page title="${i18n:_('LibrePlan: Project Status Report')}" id="reports"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<?init class="org.zkoss.zk.ui.util.Composition" arg0="/common/layout/template.zul"?>
@ -29,10 +29,6 @@
<?component name="combobox_output_format" macroURI="combobox_output_format.zul"
class="org.libreplan.web.reports.ComboboxOutputFormat" ?>
<?component name="extendedjasperreport"
class="org.libreplan.web.common.components.ExtendedJasperreport"
extends="jasperreport" ?>
<zk>
<window self="@{define(content)}"
@ -40,6 +36,32 @@
title="${i18n:_('Budget Report')}"
border="normal" >
<!-- Select project -->
<panel title="${i18n:_('Project')}"
border="normal"
style="overflow:auto">
<panelchildren>
<grid width="700px">
<columns>
<column width="200px" />
<column />
</columns>
<rows>
<row>
<label value="${i18n:_('Project')}" />
<bandboxSearch id="bandboxSelectOrder"
finder="OrderBandboxFinder"
model="@{controller.orders}"
widthListbox="480px"
widthBandbox="450px" />
</row>
</rows>
</grid>
</panelchildren>
</panel>
<separator spacing="10px" orient="horizontal" />
<!-- Select output format -->
<panel title="${i18n:_('Format')}" border="normal"
style="overflow:auto">