ItEr35S12CUCreacionUnidadesPlanificacionItEr34S12: Removing merge command
This commit is contained in:
parent
32a1885d55
commit
2be736d4af
6 changed files with 0 additions and 325 deletions
|
|
@ -28,8 +28,6 @@ import java.util.Set;
|
|||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.navalplanner.business.orders.entities.HoursGroup;
|
||||
import org.navalplanner.business.orders.entities.OrderLine;
|
||||
|
||||
/**
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
|
|
@ -86,87 +84,6 @@ public class TaskGroup extends TaskElement {
|
|||
taskElements.remove(taskElement);
|
||||
}
|
||||
|
||||
public boolean canBeMerged() {
|
||||
return isAssociatedWithAnOrderLine() && !taskElements.isEmpty()
|
||||
&& allSubTaskGroupsCanBeMerged()
|
||||
&& allChildrenHaveTheSameHoursGroup()
|
||||
&& sumOfHoursIsEqualToWorkingHours();
|
||||
}
|
||||
|
||||
private boolean allSubTaskGroupsCanBeMerged() {
|
||||
for (TaskElement t : taskElements) {
|
||||
if (t instanceof TaskGroup) {
|
||||
TaskGroup group = (TaskGroup) t;
|
||||
if (!group.canBeMerged()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean sumOfHoursIsEqualToWorkingHours() {
|
||||
int sum = 0;
|
||||
for (TaskElement taskElement : taskElements) {
|
||||
sum += taskElement.getWorkHours();
|
||||
}
|
||||
return sum == getWorkHours();
|
||||
}
|
||||
|
||||
private boolean allChildrenHaveTheSameHoursGroup() {
|
||||
HoursGroup hoursGroup = null;
|
||||
for (TaskElement taskElement : taskElements) {
|
||||
HoursGroup current = getHoursGroupFor(taskElement);
|
||||
if (current == null) {
|
||||
return false;
|
||||
}
|
||||
if (hoursGroup == null) {
|
||||
hoursGroup = current;
|
||||
}
|
||||
if (!current.equals(hoursGroup)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private HoursGroup getHoursGroupFor(TaskElement taskElement) {
|
||||
if (taskElement instanceof Task) {
|
||||
Task t = (Task) taskElement;
|
||||
return t.getHoursGroup();
|
||||
}
|
||||
return ((TaskGroup) taskElement).inferHoursGroupFromChildren();
|
||||
}
|
||||
|
||||
private boolean isAssociatedWithAnOrderLine() {
|
||||
return getOrderElement() instanceof OrderLine;
|
||||
}
|
||||
|
||||
public Task merge() {
|
||||
if (!canBeMerged()) {
|
||||
throw new IllegalStateException(
|
||||
"merge must not be called on a TaskGroup such canBeMerged returns false");
|
||||
}
|
||||
HoursGroup hoursGroup = inferHoursGroupFromChildren();
|
||||
Task result = Task.createTask(hoursGroup);
|
||||
result.copyPropertiesFrom(this);
|
||||
result.shareOfHours = this.shareOfHours;
|
||||
copyDependenciesTo(result);
|
||||
copyParenTo(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private HoursGroup inferHoursGroupFromChildren() {
|
||||
TaskElement taskElement = getChildren().get(0);
|
||||
if (taskElement instanceof Task) {
|
||||
Task t = (Task) taskElement;
|
||||
return t.getHoursGroup();
|
||||
} else {
|
||||
TaskGroup group = (TaskGroup) taskElement;
|
||||
return group.inferHoursGroupFromChildren();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResourceAllocation<?>> getResourceAllocations() {
|
||||
Set<ResourceAllocation<?>> result = new HashSet<ResourceAllocation<?>>();
|
||||
|
|
|
|||
|
|
@ -21,15 +21,12 @@
|
|||
package org.navalplanner.business.test.planner.entities;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
|
||||
import static org.navalplanner.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
@ -39,9 +36,7 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.navalplanner.business.IDataBootstrap;
|
||||
import org.navalplanner.business.orders.entities.HoursGroup;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
import org.navalplanner.business.orders.entities.OrderLine;
|
||||
import org.navalplanner.business.orders.entities.OrderLineGroup;
|
||||
import org.navalplanner.business.planner.entities.Dependency;
|
||||
import org.navalplanner.business.planner.entities.Task;
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
|
|
@ -255,135 +250,6 @@ public class TaskElementTest {
|
|||
destinationDependencyTask, Type.END_START);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theSplitMustBeEqualToTheWorkingHours() {
|
||||
HoursGroup hoursGroup = new HoursGroup();
|
||||
hoursGroup.setWorkingHours(10);
|
||||
Task taskBeingSplitted = Task.createTask(hoursGroup);
|
||||
int[][] listOfWrongShares = { { 20, 10, 3 }, { 50, 80, 10 },
|
||||
{ 90, 30, 10 }, { 10, 20 }, { 10, 110 }, { 101 }, {} };
|
||||
for (int[] shares : listOfWrongShares) {
|
||||
try {
|
||||
taskBeingSplitted.split(shares);
|
||||
fail("it should have sent an IllegalArgumentException for "
|
||||
+ Arrays.toString(shares));
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Ok
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aTaskGroupThatIsAssociatedToAnOrderLineGroupCannotBeMerged() {
|
||||
TaskGroup taskGroup = TaskGroup.create();
|
||||
taskGroup.setOrderElement(OrderLineGroup.create());
|
||||
assertFalse(taskGroup.canBeMerged());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aTaskGroupWithChildrenAssociatedWithDifferentHourGroups() {
|
||||
TaskGroup taskGroup = TaskGroup.create();
|
||||
taskGroup.setOrderElement(OrderLine.create());
|
||||
taskGroup.addTaskElement(Task.createTask(new HoursGroup()));
|
||||
taskGroup.addTaskElement(Task.createTask(new HoursGroup()));
|
||||
assertFalse(taskGroup.canBeMerged());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aTaskGroupWithoutChildrenCannotBeMerged() {
|
||||
TaskGroup taskGroup = TaskGroup.create();
|
||||
taskGroup.setOrderElement(OrderLine.create());
|
||||
assertFalse(taskGroup.canBeMerged());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aTaskGroupWithTasksThatExceedHoursCannotBeMerged() {
|
||||
TaskGroup taskGroup = TaskGroup.create();
|
||||
taskGroup.setOrderElement(OrderLine.create());
|
||||
HoursGroup hoursGroup = new HoursGroup();
|
||||
hoursGroup.setWorkingHours(10);
|
||||
taskGroup.addTaskElement(Task.createTask(hoursGroup));
|
||||
taskGroup.addTaskElement(Task.createTask(hoursGroup));
|
||||
assertFalse(taskGroup.canBeMerged());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void mergingATaskThatCannotBeMergedFails() {
|
||||
TaskGroup taskGroup = TaskGroup.create();
|
||||
taskGroup.setOrderElement(OrderLineGroup.create());
|
||||
taskGroup.merge();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergingATaskGroupSumsTheHoursOfTheChildren() {
|
||||
HoursGroup hoursGroup = new HoursGroup();
|
||||
Task taskBeingSplitted = Task.createTask(hoursGroup);
|
||||
taskBeingSplitted.setName("prueba");
|
||||
taskBeingSplitted.setNotes("blabla");
|
||||
taskBeingSplitted.setStartDate(new Date());
|
||||
OrderLine orderLine = OrderLine.create();
|
||||
hoursGroup.setWorkingHours(100);
|
||||
orderLine.addHoursGroup(hoursGroup);
|
||||
taskBeingSplitted.setOrderElement(orderLine);
|
||||
int[] shares = { 20, 30, 50 };
|
||||
TaskGroup taskGroup = taskBeingSplitted.split(shares);
|
||||
Task task = taskGroup.merge();
|
||||
checkPopertiesAreKept(taskGroup, task);
|
||||
assertThat(task.getHoursGroup(), equalTo(hoursGroup));
|
||||
assertThat(task.getOrderElement(), equalTo((OrderElement) orderLine));
|
||||
assertThat(task.getWorkHours(), equalTo(100));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergingATaskCanResultInATaskWithAShareOfHours() {
|
||||
HoursGroup hoursGroup = new HoursGroup();
|
||||
Task taskBeingSplitted = Task.createTask(hoursGroup);
|
||||
OrderLine orderLine = OrderLine.create();
|
||||
hoursGroup.setWorkingHours(100);
|
||||
orderLine.addHoursGroup(hoursGroup);
|
||||
taskBeingSplitted.setOrderElement(orderLine);
|
||||
int[] shares = { 20, 30, 50 };
|
||||
TaskGroup taskGroup = taskBeingSplitted.split(shares);
|
||||
Task subTask = (Task) taskGroup.getChildren().get(0);
|
||||
TaskGroup group = subTask.split(new int[] { 10, 10 });
|
||||
Task merged = group.merge();
|
||||
assertThat(merged.getWorkHours(), equalTo(20));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergingATaskKeepsDependencies() {
|
||||
HoursGroup hoursGroup = new HoursGroup();
|
||||
Task taskBeingSplitted = Task.createTask(hoursGroup);
|
||||
OrderLine orderLine = OrderLine.create();
|
||||
hoursGroup.setWorkingHours(100);
|
||||
orderLine.addHoursGroup(hoursGroup);
|
||||
taskBeingSplitted.setOrderElement(orderLine);
|
||||
int[] shares = { 20, 30, 50 };
|
||||
TaskGroup taskGroup = taskBeingSplitted.split(shares);
|
||||
Task source = Task.createTask(new HoursGroup());
|
||||
Task destination = Task.createTask(new HoursGroup());
|
||||
addDependenciesForChecking(taskGroup, source, destination);
|
||||
Task transformed = taskGroup.merge();
|
||||
checkDependenciesAreKept(transformed, source, destination);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theMergedEntityHasTheSameParent() {
|
||||
HoursGroup hoursGroup = new HoursGroup();
|
||||
Task taskBeingSplitted = Task.createTask(hoursGroup);
|
||||
OrderLine orderLine = OrderLine.create();
|
||||
hoursGroup.setWorkingHours(100);
|
||||
orderLine.addHoursGroup(hoursGroup);
|
||||
taskBeingSplitted.setOrderElement(orderLine);
|
||||
int[] shares = { 20, 30, 50 };
|
||||
TaskGroup parent = taskBeingSplitted.split(shares);
|
||||
Task subTask = (Task) parent.getChildren().get(0);
|
||||
TaskGroup group = subTask.split(new int[] { 10, 10 });
|
||||
Task merged = group.merge();
|
||||
assertThat(merged.getParent(), equalTo(parent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void detachRemovesDependenciesFromRelatedTasks() {
|
||||
HoursGroup hoursGroup = new HoursGroup();
|
||||
Task taskToDetach = Task.createTask(hoursGroup);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ import org.navalplanner.web.planner.loadchart.LoadChart;
|
|||
import org.navalplanner.web.planner.loadchart.LoadChartFiller;
|
||||
import org.navalplanner.web.planner.milestone.IAddMilestoneCommand;
|
||||
import org.navalplanner.web.planner.order.ISaveCommand.IAfterSaveListener;
|
||||
import org.navalplanner.web.planner.splitting.IMergeTaskCommand;
|
||||
import org.navalplanner.web.planner.splitting.ISplitTaskCommand;
|
||||
import org.navalplanner.web.planner.splitting.SplittingController;
|
||||
import org.navalplanner.web.planner.taskedition.EditTaskController;
|
||||
|
|
@ -140,7 +139,6 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
configuration.addCommandOnTask(buildResourceAllocationCommand(resourceAllocationController));
|
||||
configuration.addCommandOnTask(buildSplitCommand(splittingController));
|
||||
configuration.addCommandOnTask(buildMergeTaskCommand());
|
||||
configuration.addCommandOnTask(buildMilestoneCommand());
|
||||
configuration
|
||||
.addCommandOnTask(buildCalendarAllocationCommand(calendarAllocationController));
|
||||
|
|
@ -199,12 +197,6 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
return addMilestoneCommand;
|
||||
}
|
||||
|
||||
private IMergeTaskCommand buildMergeTaskCommand() {
|
||||
IMergeTaskCommand mergeCommand = getMergeTaskCommand();
|
||||
mergeCommand.setState(planningState);
|
||||
return mergeCommand;
|
||||
}
|
||||
|
||||
private ISplitTaskCommand buildSplitCommand(
|
||||
SplittingController splittingController) {
|
||||
ISplitTaskCommand splitCommand = getSplitCommand();
|
||||
|
|
@ -329,8 +321,6 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
protected abstract ISplitTaskCommand getSplitCommand();
|
||||
|
||||
protected abstract IMergeTaskCommand getMergeTaskCommand();
|
||||
|
||||
protected abstract IAddMilestoneCommand getAddMilestoneCommand();
|
||||
|
||||
protected abstract IEditTaskCommand getEditTaskCommand();
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.web.planner.splitting;
|
||||
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.navalplanner.web.planner.order.PlanningState;
|
||||
import org.zkoss.ganttz.extensions.ICommandOnTask;
|
||||
|
||||
public interface IMergeTaskCommand extends ICommandOnTask<TaskElement> {
|
||||
|
||||
public void setState(PlanningState planningState);
|
||||
|
||||
}
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.web.planner.splitting;
|
||||
|
||||
import org.navalplanner.business.planner.entities.Task;
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.navalplanner.business.planner.entities.TaskGroup;
|
||||
import org.navalplanner.web.planner.order.PlanningState;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.zkoss.ganttz.extensions.IContextWithPlannerTask;
|
||||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
@Component
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class MergeTaskCommand implements IMergeTaskCommand {
|
||||
|
||||
private PlanningState planningState;
|
||||
|
||||
@Override
|
||||
public void setState(PlanningState planningState) {
|
||||
this.planningState = planningState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAction(IContextWithPlannerTask<TaskElement> context,
|
||||
TaskElement task) {
|
||||
if (!(task instanceof TaskGroup)) {
|
||||
return;
|
||||
}
|
||||
TaskGroup old = (TaskGroup) task;
|
||||
if (!old.canBeMerged()) {
|
||||
return;
|
||||
}
|
||||
Task result = old.merge();
|
||||
context.replace(old, result);
|
||||
planningState.removed(old);
|
||||
planningState.added(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return _("Merge");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -28,7 +28,6 @@
|
|||
<lookup-method name="getSaveCommand" bean="saveCommand"/>
|
||||
<lookup-method name="getResourceAllocationCommand" bean="resourceAllocationCommand"/>
|
||||
<lookup-method name="getSplitCommand" bean="splitTaskCommand"/>
|
||||
<lookup-method name="getMergeTaskCommand" bean="mergeTaskCommand"/>
|
||||
<lookup-method name="getEditTaskCommand" bean="editTaskCommand"/>
|
||||
<lookup-method name="getCalendarAllocationCommand" bean="calendarAllocationCommand"/>
|
||||
<lookup-method name="getAddMilestoneCommand" bean="addMilestoneCommand"/>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue