diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/GraphicForStreches.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/GraphicForStreches.java
new file mode 100644
index 000000000..185a975a1
--- /dev/null
+++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/GraphicForStreches.java
@@ -0,0 +1,166 @@
+/*
+ * This file is part of ###PROJECT_NAME###
+ *
+ * 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.planner.allocation.streches;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.List;
+
+import org.joda.time.Days;
+import org.joda.time.LocalDate;
+import org.navalplanner.business.calendars.entities.BaseCalendar;
+import org.navalplanner.business.planner.entities.Stretch;
+import org.navalplanner.business.planner.entities.StretchesFunction.Type;
+import org.navalplanner.web.planner.allocation.streches.StretchesFunctionController.IGraphicGenerator;
+import org.zkoss.zul.SimpleXYModel;
+import org.zkoss.zul.XYModel;
+
+/**
+ * @author Óscar González Fernández
+ *
+ */
+public abstract class GraphicForStreches implements IGraphicGenerator {
+
+ public static IGraphicGenerator forType(Type type) {
+ switch (type) {
+ case DEFAULT:
+ return new ForDefaultStreches();
+ case INTERPOLATED:
+ return new ForInterpolation();
+ default:
+ throw new RuntimeException();
+ }
+ }
+
+ private static class ForDefaultStreches extends GraphicForStreches {
+
+ @Override
+ public boolean areChartsEnabled(IStretchesFunctionModel model) {
+ return true;
+ }
+
+ @Override
+ public XYModel getAccumulatedHoursChartData(
+ IStretchesFunctionModel stretchesFunctionModel) {
+ XYModel xymodel = new SimpleXYModel();
+
+ List stretches = stretchesFunctionModel.getStretches();
+ if (stretches.isEmpty()) {
+ return xymodel;
+ }
+
+ String title = "percentage";
+
+ LocalDate startDate = stretchesFunctionModel.getTaskStartDate();
+ xymodel.addValue(title, startDate.toDateTimeAtStartOfDay()
+ .getMillis(), 0);
+
+ BigDecimal taskHours = new BigDecimal(stretchesFunctionModel
+ .getTaskHours());
+
+ for (Stretch stretch : stretches) {
+ BigDecimal amountWork = stretch.getAmountWorkPercentage()
+ .multiply(taskHours);
+
+ xymodel.addValue(title, stretch.getDate()
+ .toDateTimeAtStartOfDay().getMillis(), amountWork);
+ }
+
+ return xymodel;
+ }
+
+ @Override
+ public XYModel getDedicationChart(
+ IStretchesFunctionModel stretchesFunctionModel) {
+ XYModel xymodel = new SimpleXYModel();
+
+ List stretches = stretchesFunctionModel.getStretches();
+ if (stretches.isEmpty()) {
+ return xymodel;
+ }
+
+ String title = "hours";
+
+ LocalDate previousDate = stretchesFunctionModel.getTaskStartDate();
+ BigDecimal previousPercentage = BigDecimal.ZERO;
+
+ BigDecimal taskHours = new BigDecimal(stretchesFunctionModel
+ .getTaskHours());
+ BaseCalendar calendar = stretchesFunctionModel.getTaskCalendar();
+
+ xymodel.addValue(title, previousDate.toDateTimeAtStartOfDay()
+ .getMillis(), 0);
+
+ for (Stretch stretch : stretches) {
+ BigDecimal amountWork = stretch.getAmountWorkPercentage()
+ .subtract(previousPercentage).multiply(taskHours);
+ Integer days = Days
+ .daysBetween(previousDate, stretch.getDate()).getDays();
+
+ if (calendar != null) {
+ days -= calendar.getNonWorkableDays(previousDate,
+ stretch.getDate()).size();
+ }
+
+ BigDecimal hoursPerDay = BigDecimal.ZERO;
+ if (days > 0) {
+ hoursPerDay = amountWork.divide(new BigDecimal(days),
+ RoundingMode.DOWN);
+ }
+
+ xymodel.addValue(title, previousDate.toDateTimeAtStartOfDay()
+ .getMillis() + 1, hoursPerDay);
+ xymodel.addValue(title, stretch.getDate()
+ .toDateTimeAtStartOfDay().getMillis(), hoursPerDay);
+
+ previousDate = stretch.getDate();
+ previousPercentage = stretch.getAmountWorkPercentage();
+ }
+
+ xymodel.addValue(title, previousDate.toDateTimeAtStartOfDay()
+ .getMillis() + 1, 0);
+
+ return xymodel;
+ }
+
+ }
+
+ private static class ForInterpolation extends GraphicForStreches {
+
+ @Override
+ public boolean areChartsEnabled(IStretchesFunctionModel model) {
+ return false;
+ }
+
+ @Override
+ public XYModel getAccumulatedHoursChartData(
+ IStretchesFunctionModel stretchesFunctionModel) {
+ return new SimpleXYModel();
+ }
+
+ @Override
+ public XYModel getDedicationChart(
+ IStretchesFunctionModel stretchesFunctionModel) {
+ return new SimpleXYModel();
+ }
+
+ }
+
+}
diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StrechesFunctionConfiguration.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StrechesFunctionConfiguration.java
index 336e5e076..597c515a5 100644
--- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StrechesFunctionConfiguration.java
+++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StrechesFunctionConfiguration.java
@@ -27,6 +27,7 @@ import org.navalplanner.business.planner.entities.StretchesFunction;
import org.navalplanner.business.planner.entities.StretchesFunction.Type;
import org.navalplanner.web.common.Util;
import org.navalplanner.web.planner.allocation.IAssignmentFunctionConfiguration;
+import org.navalplanner.web.planner.allocation.streches.StretchesFunctionController.IGraphicGenerator;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zul.api.Window;
@@ -40,9 +41,9 @@ public abstract class StrechesFunctionConfiguration implements
@Override
public void goToConfigure() {
- StretchesFunctionController stretchesFunctionController = new StretchesFunctionController();
+ StretchesFunctionController stretchesFunctionController = new StretchesFunctionController(
+ getGraphicsGenerators());
stretchesFunctionController.setTitle(getTitle());
- stretchesFunctionController.setChartsEnabled(getChartsEnabled());
HashMap args = new HashMap();
args.put("stretchesFunctionController", stretchesFunctionController);
Window window = (Window) Executions.createComponents(
@@ -58,6 +59,10 @@ public abstract class StrechesFunctionConfiguration implements
assignmentFunctionChanged();
}
+ private IGraphicGenerator getGraphicsGenerators() {
+ return GraphicForStreches.forType(getType());
+ }
+
protected abstract Type getType();
protected abstract boolean getChartsEnabled();
diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionController.java
index 72467eeae..bfe3d3905 100644
--- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionController.java
+++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionController.java
@@ -27,9 +27,7 @@ import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
-import org.joda.time.Days;
-import org.joda.time.LocalDate;
-import org.navalplanner.business.calendars.entities.BaseCalendar;
+import org.apache.commons.lang.Validate;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.planner.entities.AssignmentFunction;
import org.navalplanner.business.planner.entities.ResourceAllocation;
@@ -52,12 +50,22 @@ import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;
import org.zkoss.zul.Messagebox;
-import org.zkoss.zul.SimpleXYModel;
import org.zkoss.zul.XYModel;
import org.zkoss.zul.api.Window;
public class StretchesFunctionController extends GenericForwardComposer {
+ public interface IGraphicGenerator {
+
+ public boolean areChartsEnabled(IStretchesFunctionModel model);
+
+ XYModel getDedicationChart(
+ IStretchesFunctionModel stretchesFunctionModel);
+
+ XYModel getAccumulatedHoursChartData(
+ IStretchesFunctionModel stretchesFunctionModel);
+
+ }
private Window window;
private IStretchesFunctionModel stretchesFunctionModel;
@@ -66,7 +74,12 @@ public class StretchesFunctionController extends GenericForwardComposer {
private String title;
- private boolean chartsEnabled = true;
+ private final IGraphicGenerator graphicGenerator;
+
+ public StretchesFunctionController(IGraphicGenerator graphicGenerator) {
+ Validate.notNull(graphicGenerator);
+ this.graphicGenerator = graphicGenerator;
+ }
@Override
public void doAfterCompose(Component comp) throws Exception {
@@ -262,83 +275,12 @@ public class StretchesFunctionController extends GenericForwardComposer {
}
public XYModel getDedicationChartData() {
- XYModel xymodel = new SimpleXYModel();
-
- List stretches = stretchesFunctionModel.getStretches();
- if (stretches.isEmpty()) {
- return xymodel;
- }
-
- String title = "hours";
-
- LocalDate previousDate = stretchesFunctionModel.getTaskStartDate();
- BigDecimal previousPercentage = BigDecimal.ZERO;
-
- BigDecimal taskHours = new BigDecimal(stretchesFunctionModel
- .getTaskHours());
- BaseCalendar calendar = stretchesFunctionModel.getTaskCalendar();
-
- xymodel.addValue(title, previousDate.toDateTimeAtStartOfDay()
- .getMillis(), 0);
-
- for (Stretch stretch : stretches) {
- BigDecimal amountWork = stretch.getAmountWorkPercentage().subtract(
- previousPercentage).multiply(taskHours);
- Integer days = Days.daysBetween(previousDate, stretch.getDate())
- .getDays();
-
- if (calendar != null) {
- days -= calendar.getNonWorkableDays(previousDate, stretch
- .getDate()).size();
- }
-
- BigDecimal hoursPerDay = BigDecimal.ZERO;
- if (days > 0) {
- hoursPerDay = amountWork.divide(new BigDecimal(days),
- RoundingMode.DOWN);
- }
-
- xymodel.addValue(title, previousDate.toDateTimeAtStartOfDay()
- .getMillis() + 1, hoursPerDay);
- xymodel.addValue(title, stretch.getDate().toDateTimeAtStartOfDay()
- .getMillis(), hoursPerDay);
-
- previousDate = stretch.getDate();
- previousPercentage = stretch.getAmountWorkPercentage();
- }
-
- xymodel.addValue(title, previousDate.toDateTimeAtStartOfDay()
- .getMillis() + 1, 0);
-
- return xymodel;
+ return graphicGenerator.getDedicationChart(stretchesFunctionModel);
}
public XYModel getAccumulatedHoursChartData() {
- XYModel xymodel = new SimpleXYModel();
-
- List stretches = stretchesFunctionModel.getStretches();
- if (stretches.isEmpty()) {
- return xymodel;
- }
-
- String title = "percentage";
-
- LocalDate startDate = stretchesFunctionModel.getTaskStartDate();
- xymodel.addValue(title, startDate.toDateTimeAtStartOfDay().getMillis(),
- 0);
-
- BigDecimal taskHours = new BigDecimal(stretchesFunctionModel
- .getTaskHours());
-
- for (Stretch stretch : stretches) {
- BigDecimal amountWork = stretch.getAmountWorkPercentage().multiply(
- taskHours);
-
- xymodel.addValue(title, stretch.getDate().toDateTimeAtStartOfDay()
- .getMillis(), amountWork);
- }
-
- return xymodel;
+ return graphicGenerator
+ .getAccumulatedHoursChartData(stretchesFunctionModel);
}
public String getTitle() {
@@ -350,11 +292,7 @@ public class StretchesFunctionController extends GenericForwardComposer {
}
public boolean isChartsEnabled() {
- return chartsEnabled;
- }
-
- public void setChartsEnabled(boolean chartsEnabled) {
- this.chartsEnabled = chartsEnabled;
+ return graphicGenerator.areChartsEnabled(stretchesFunctionModel);
}
}