diff --git a/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/ProjectStatusReportDTO.java b/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/ProjectStatusReportDTO.java new file mode 100644 index 000000000..7982a294d --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/reports/dtos/ProjectStatusReportDTO.java @@ -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 . + */ + +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 + */ +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(); + } + +} \ No newline at end of file diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/reports/IProjectStatusReportModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/reports/IProjectStatusReportModel.java new file mode 100644 index 000000000..774041a75 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/web/reports/IProjectStatusReportModel.java @@ -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 . + */ + +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 + */ +public interface IProjectStatusReportModel { + + List getOrders(); + + List getProjectStatusReportDTOs(Order order); + +} diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/reports/ProjectStatusReportController.java b/libreplan-webapp/src/main/java/org/libreplan/web/reports/ProjectStatusReportController.java index 9cd0c04fc..1976af9db 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/reports/ProjectStatusReportController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/reports/ProjectStatusReportController.java @@ -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 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 getOrders() { + return projectStatusReportModel.getOrders(); + } + + @Override + protected Map getParameters() { + Map result = super.getParameters(); + + Order order = getSelectedOrder(); + result.put("project", order.getName() + " (" + order.getCode() + ")"); + return result; + } } \ No newline at end of file diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/reports/ProjectStatusReportModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/reports/ProjectStatusReportModel.java new file mode 100644 index 000000000..4f7a1de72 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/web/reports/ProjectStatusReportModel.java @@ -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 . + */ + +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 + */ +@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 getOrders() { + List result = orderDAO.getOrdersByReadAuthorizationByScenario( + SecurityUtils.getSessionUserLoginName(), + scenarioManager.getCurrent()); + Collections.sort(result); + return result; + } + + @Override + @Transactional(readOnly = true) + public List getProjectStatusReportDTOs(Order order) { + orderDAO.reattach(order); + + order.useSchedulingDataFor(scenarioManager.getCurrent()); + + List dtos = new ArrayList(); + + for (OrderElement child : order.getAllChildren()) { + dtos.add(new ProjectStatusReportDTO(child)); + } + + return dtos; + } + +} \ No newline at end of file diff --git a/libreplan-webapp/src/main/webapp/reports/projectStatusReport.zul b/libreplan-webapp/src/main/webapp/reports/projectStatusReport.zul index d4a8cd532..f23c8777d 100644 --- a/libreplan-webapp/src/main/webapp/reports/projectStatusReport.zul +++ b/libreplan-webapp/src/main/webapp/reports/projectStatusReport.zul @@ -17,7 +17,7 @@ along with this program. If not, see . --> - + @@ -29,10 +29,6 @@ - - + + + + + + + + + + + + + + + + + +