ItEr17S10CUCreacionProxectoPlanificacionItEr16S12: Adding save command that will save the changes done to the tasks elements.
This commit is contained in:
parent
df7be5d6ac
commit
b9f13d3457
4 changed files with 72 additions and 1 deletions
|
|
@ -0,0 +1,16 @@
|
|||
package org.navalplanner.web.planner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.zkoss.ganttz.extensions.ICommand;
|
||||
|
||||
/**
|
||||
* Contract for {@link SaveCommand} <br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public interface ISaveCommand extends ICommand<TaskElement> {
|
||||
|
||||
public void setState(List<TaskElement> taskElements);
|
||||
|
||||
}
|
||||
|
|
@ -46,7 +46,11 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
if (!orderReloaded.isSomeTaskElementScheduled())
|
||||
throw new IllegalArgumentException("the order " + order
|
||||
+ " must be scheduled");
|
||||
onTransaction.use(createConfiguration(orderReloaded));
|
||||
PlannerConfiguration<TaskElement> configuration = createConfiguration(orderReloaded);
|
||||
ISaveCommand saveCommand = getSaveCommand();
|
||||
saveCommand.setState(state);
|
||||
configuration.addGlobalCommand(saveCommand);
|
||||
onTransaction.use(configuration);
|
||||
}
|
||||
|
||||
private PlannerConfiguration<TaskElement> createConfiguration(
|
||||
|
|
@ -76,6 +80,8 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
// spring method injection
|
||||
protected abstract ITaskElementAdapter getTaskElementAdapter();
|
||||
|
||||
protected abstract ISaveCommand getSaveCommand();
|
||||
|
||||
private Order reload(Order order) {
|
||||
try {
|
||||
return orderService.find(order.getId());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
package org.navalplanner.web.planner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.navalplanner.business.planner.services.ITaskElementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.zkoss.ganttz.extensions.IContext;
|
||||
|
||||
@Component
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
/**
|
||||
* A command that saves the changes in the taskElements.
|
||||
* It can be considered the final step in the conversation <br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public class SaveCommand implements ISaveCommand {
|
||||
|
||||
@Autowired
|
||||
private ITaskElementService taskElementService;
|
||||
|
||||
private List<TaskElement> taskElements;
|
||||
|
||||
@Override
|
||||
public void setState(List<TaskElement> taskElements) {
|
||||
this.taskElements = taskElements;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void doAction(IContext<TaskElement> context) {
|
||||
for (TaskElement taskElement : taskElements) {
|
||||
taskElementService.save(taskElement);
|
||||
}
|
||||
// TODO redirect to another page or show message
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Gardar";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
<bean class="org.navalplanner.web.planner.OrderPlanningModel" scope="prototype">
|
||||
<lookup-method name="getTaskElementAdapter" bean="taskElementAdapter"/>
|
||||
<lookup-method name="getSaveCommand" bean="saveCommand"/>
|
||||
</bean>
|
||||
|
||||
<context:component-scan base-package="org.navalplanner.web"/>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue