ItEr09S08HistoriaLaboralTraballadorItEr08S11: Add work relationships view window
Implemented WorkRelationships view Use Case Modified controller structure to satisfy behaviour defined
This commit is contained in:
parent
906c9763d9
commit
f0eeed0ca5
15 changed files with 173 additions and 15 deletions
|
|
@ -49,7 +49,11 @@ public class CriterionSatisfaction {
|
|||
}
|
||||
|
||||
public Date getEndDate() {
|
||||
return new Date(finishDate.getTime());
|
||||
if (isFinished() ) {
|
||||
return new Date(finishDate.getTime());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Criterion getCriterion() {
|
||||
|
|
@ -85,4 +89,15 @@ public class CriterionSatisfaction {
|
|||
return finishDate != null;
|
||||
}
|
||||
|
||||
public void setEndDate(Date date) {
|
||||
if ( (startDate.equals(date) || startDate.before(date)) )
|
||||
finishDate = date;
|
||||
}
|
||||
|
||||
public void setStartDate(Date date) {
|
||||
if ( (finishDate == null || finishDate.after(date)) )
|
||||
startDate = date;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
package org.navalplanner.business.resources.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public enum LeaveCriterions {
|
||||
MEDICAL_LEAVE("medicalLeaveWorkingRelationship"), PATERNITY_LEAVE(
|
||||
"paternityLeaveWorkingRelationship");
|
||||
|
||||
public static List<Criterion> getCriterions() {
|
||||
ArrayList<Criterion> result = new ArrayList<Criterion>();
|
||||
for (LeaveCriterions leaveCriterions : values()) {
|
||||
result.add(leaveCriterions.criterion());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private final String criterionName;
|
||||
|
||||
private LeaveCriterions(String name) {
|
||||
this.criterionName = name;
|
||||
}
|
||||
|
||||
public Criterion criterion() {
|
||||
return PredefinedCriterionTypes.LEAVE
|
||||
.createCriterion(criterionName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -16,11 +16,16 @@ public enum PredefinedCriterionTypes implements ICriterionType<Criterion> {
|
|||
}
|
||||
},
|
||||
LOCATION_GROUP(false, true, true, true, Resource.class) {
|
||||
|
||||
@Override
|
||||
public List<Criterion> getPredefined() {
|
||||
return Arrays.asList();
|
||||
}
|
||||
},
|
||||
LEAVE(false, false, false, false, Worker.class) {
|
||||
@Override
|
||||
public List<Criterion> getPredefined() {
|
||||
return LeaveCriterions.getCriterions();
|
||||
}
|
||||
};
|
||||
|
||||
private final boolean allowHierarchy;
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public abstract class Resource {
|
|||
}
|
||||
|
||||
public Set<CriterionSatisfaction> getAllSatisfactions() {
|
||||
return Collections.unmodifiableSet(criterionSatisfactions);
|
||||
return new HashSet(criterionSatisfactions);
|
||||
}
|
||||
|
||||
public Collection<CriterionSatisfaction> getSatisfactionsFor(
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
//import org.navalplanner.business.resources.entities.CriterionSatisfaction;
|
||||
import org.navalplanner.business.resources.entities.ICriterion;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import java.util.Set;
|
|||
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.resources.daos.IResourceDao;
|
||||
|
||||
import org.navalplanner.business.resources.entities.ICriterion;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
<version access="field" name="version" type="long"/>
|
||||
<property access="field" name="startDate" not-null="true"/>
|
||||
<property access="field" name="finishDate"/>
|
||||
<many-to-one name="criterion" access="field" not-null="true">
|
||||
<many-to-one name="criterion" access="field" not-null="true" lazy="false">
|
||||
<column name="name" not-null="true"></column>
|
||||
<column name="type" not-null="true"></column>
|
||||
</many-to-one>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package org.navalplanner.web.resources;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import java.util.Set;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.resources.entities.CriterionSatisfaction;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
|
||||
/**
|
||||
|
|
@ -21,4 +23,5 @@ public interface IWorkerModel {
|
|||
|
||||
void prepareEditFor(Worker worker);
|
||||
|
||||
}
|
||||
Set<CriterionSatisfaction> getCriterionSatisfactions(Worker worker);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
package org.navalplanner.web.resources;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.navalplanner.business.resources.entities.CriterionSatisfaction;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
|
||||
/**
|
||||
* Subcontroller for {@link Worker} resource <br />
|
||||
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
|
||||
*/
|
||||
public class WorkRelationshipsController extends GenericForwardComposer {
|
||||
|
||||
private IWorkerModel workerModel;
|
||||
private WorkerCRUDController workerCRUDController;
|
||||
|
||||
public WorkRelationshipsController(IWorkerModel workerModel,
|
||||
WorkerCRUDController workerCRUDController) {
|
||||
this.workerModel = workerModel;
|
||||
this.workerCRUDController = workerCRUDController;
|
||||
}
|
||||
|
||||
public Set<CriterionSatisfaction> getCriterionSatisfactions() {
|
||||
if (this.workerCRUDController.getWorker() == null) {
|
||||
return new HashSet();
|
||||
} else {
|
||||
return workerModel.getCriterionSatisfactions(
|
||||
this.workerCRUDController.getWorker());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
package org.navalplanner.web.resources;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.validator.InvalidValue;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.CriterionSatisfaction;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
import org.navalplanner.web.common.IMessagesForUser;
|
||||
import org.navalplanner.web.common.Level;
|
||||
|
|
@ -26,6 +29,8 @@ public class WorkerCRUDController extends GenericForwardComposer {
|
|||
|
||||
private Window editWindow;
|
||||
|
||||
private Window workRelationshipsWindow;
|
||||
|
||||
private IWorkerModel workerModel;
|
||||
|
||||
private OnlyOneVisible visibility;
|
||||
|
|
@ -34,15 +39,18 @@ public class WorkerCRUDController extends GenericForwardComposer {
|
|||
|
||||
private Component messagesContainer;
|
||||
|
||||
private GenericForwardComposer workRelationship;
|
||||
|
||||
public WorkerCRUDController() {
|
||||
}
|
||||
|
||||
public WorkerCRUDController(Window createWindow, Window listWindow,
|
||||
Window editWindow, IWorkerModel workerModel,
|
||||
IMessagesForUser messages) {
|
||||
Window editWindow, Window workRelationshipsWindow,
|
||||
IWorkerModel workerModel, IMessagesForUser messages) {
|
||||
this.createWindow = createWindow;
|
||||
this.listWindow = listWindow;
|
||||
this.editWindow = editWindow;
|
||||
this.workRelationshipsWindow = workRelationshipsWindow;
|
||||
this.workerModel = workerModel;
|
||||
this.messages = messages;
|
||||
}
|
||||
|
|
@ -78,6 +86,11 @@ public class WorkerCRUDController extends GenericForwardComposer {
|
|||
Util.reloadBindings(editWindow);
|
||||
}
|
||||
|
||||
public void goToWorkRelationshipsForm(Worker worker) {
|
||||
getVisibility().showOnly(workRelationshipsWindow);
|
||||
Util.reloadBindings(workRelationshipsWindow);
|
||||
}
|
||||
|
||||
public void goToCreateForm() {
|
||||
workerModel.prepareForCreate();
|
||||
getVisibility().showOnly(createWindow);
|
||||
|
|
@ -92,14 +105,20 @@ public class WorkerCRUDController extends GenericForwardComposer {
|
|||
if (messagesContainer == null)
|
||||
throw new RuntimeException("messagesContainer is needed");
|
||||
messages = new MessagesForUser(messagesContainer);
|
||||
this.workRelationship =
|
||||
new WorkRelationshipsController(this.workerModel,this);
|
||||
}
|
||||
|
||||
private OnlyOneVisible getVisibility() {
|
||||
if (visibility == null) {
|
||||
visibility = new OnlyOneVisible(listWindow, editWindow,
|
||||
createWindow);
|
||||
createWindow, workRelationshipsWindow );
|
||||
}
|
||||
return visibility;
|
||||
}
|
||||
|
||||
}
|
||||
public GenericForwardComposer getWorkRelationship() {
|
||||
return this.workRelationship;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,9 +7,12 @@ import org.hibernate.validator.ClassValidator;
|
|||
import org.hibernate.validator.InvalidValue;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import java.util.Set;
|
||||
import org.navalplanner.business.resources.entities.CriterionSatisfaction;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
import org.navalplanner.business.resources.services.ResourceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Model for worker <br />
|
||||
|
|
@ -45,6 +48,7 @@ public class WorkerModel implements IWorkerModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
|
||||
public Worker getWorker() {
|
||||
return worker;
|
||||
}
|
||||
|
|
@ -55,6 +59,7 @@ public class WorkerModel implements IWorkerModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly=true)
|
||||
public void prepareEditFor(Worker worker) {
|
||||
Validate.notNull(worker, "worker is not null");
|
||||
try {
|
||||
|
|
@ -62,6 +67,12 @@ public class WorkerModel implements IWorkerModel {
|
|||
} catch (InstanceNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
this.worker.getAllSatisfactions();
|
||||
for ( CriterionSatisfaction cs : this.worker.getAllSatisfactions() ) {}
|
||||
}
|
||||
|
||||
public Set<CriterionSatisfaction> getCriterionSatisfactions(Worker worker) {
|
||||
return worker.getAllSatisfactions();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,4 +26,8 @@
|
|||
</grid>
|
||||
<button onClick="controller.save();" label="${arg.save_button_label}" />
|
||||
<button onClick="controller.cancel();" label="${arg.cancel_button_label}" />
|
||||
<button label="Work Relationships"
|
||||
onClick="controller.goToWorkRelationshipsForm(controller.worker)">
|
||||
</button>
|
||||
|
||||
</window>
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<window id="${arg.top_id}" title="${arg.title}"
|
||||
apply="${controller.workRelationshipsController}">
|
||||
<grid id="history"
|
||||
model="@{controller.workRelationship.criterionSatisfactions}"
|
||||
mold="paging" pageSize="5">
|
||||
<columns>
|
||||
<column label="Date start"/>
|
||||
<column label="Date end"/>
|
||||
<column label="Relationship"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row self="@{each='criterionSatisfaction'}"
|
||||
value="@{criterionSatisfaction}">
|
||||
<datebox id="date_start"
|
||||
value="@{criterionSatisfaction.startDate}" width="150px" />
|
||||
<!--datebox id="date_start"
|
||||
value="@{criterionSatisfaction.startDate}"
|
||||
onChange="controller.goToEditForm();"
|
||||
width="150px" /-->
|
||||
<datebox id="date_end"
|
||||
value="@{criterionSatisfaction.endDate}" width="150px" />
|
||||
<label value="@{criterionSatisfaction.criterion.name}" />
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
<button onClick="controller.save();" label="${arg.save_button_label}" />
|
||||
<button onClick="controller.cancel();" label="${arg.cancel_button_label}" />
|
||||
<button label="Edit personal data"
|
||||
onClick="controller.goToEditForm(controller.worker)">
|
||||
</button>
|
||||
</window>
|
||||
|
|
@ -7,6 +7,7 @@
|
|||
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
|
||||
<?component name="list" inline="true" macroURI="_list.zul"?>
|
||||
<?component name="edition" inline="true" macroURI="_edition.zul"?>
|
||||
<?component name="workRelationships" inline="true" macroURI="_workRelationships.zul"?>
|
||||
<zk>
|
||||
<window self="@{define(content)}"
|
||||
apply="org.navalplanner.web.resources.WorkerCRUDController"
|
||||
|
|
@ -16,7 +17,9 @@
|
|||
<list top_id="listWindow" />
|
||||
<edition top_id="createWindow" title="Create"
|
||||
save_button_label="Save" cancel_button_label="Cancel" />
|
||||
<edition top_id="editWindow" title="Edit"
|
||||
<edition top_id="editWindow" title="Edit Personal Data"
|
||||
save_button_label="Save" cancel_button_label="Cancel" />
|
||||
<workRelationships top_id="workRelationshipsWindow" title="Work Relationships"
|
||||
save_button_label="Save" cancel_button_label="Cancel" />
|
||||
</window>
|
||||
</zk>
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ public class WorkerCRUDControllerTest {
|
|||
private Window createWindow;
|
||||
private Window listWindow;
|
||||
private Window editWindow;
|
||||
private Window workRelationshipsWindow;
|
||||
|
||||
private WorkerCRUDController createControllerForModel(
|
||||
IWorkerModel workerModel) {
|
||||
|
|
@ -39,12 +40,15 @@ public class WorkerCRUDControllerTest {
|
|||
createWindow = createNiceMock(Window.class);
|
||||
listWindow = createNiceMock(Window.class);
|
||||
editWindow = createNiceMock(Window.class);
|
||||
workRelationshipsWindow = createNiceMock(Window.class);
|
||||
|
||||
WorkerCRUDController workerCRUDController = new WorkerCRUDController(
|
||||
createWindow, listWindow, editWindow, workerModel, messages);
|
||||
createWindow, listWindow, editWindow, workRelationshipsWindow,
|
||||
workerModel, messages);
|
||||
return workerCRUDController;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSave() throws Exception {
|
||||
IWorkerModel workerModel = createMock(IWorkerModel.class);
|
||||
|
|
@ -53,7 +57,7 @@ public class WorkerCRUDControllerTest {
|
|||
|
||||
WorkerCRUDController workerCRUDController = createControllerForModel(
|
||||
workerModel, messagesForUser);
|
||||
replay(createWindow, listWindow, editWindow);
|
||||
replay(createWindow, listWindow, editWindow, workRelationshipsWindow);
|
||||
// expectations
|
||||
workerModel.prepareForCreate();
|
||||
expect(workerModel.getWorker()).andReturn(workerToReturn).anyTimes();
|
||||
|
|
@ -82,7 +86,8 @@ public class WorkerCRUDControllerTest {
|
|||
expect(createWindow.setVisible(true)).andReturn(false);
|
||||
expect(createWindow.setVisible(false)).andReturn(true);
|
||||
expect(listWindow.setVisible(true)).andReturn(false);
|
||||
replay(createWindow, listWindow, editWindow, workerModel);
|
||||
expect(workRelationshipsWindow.setVisible(true)).andReturn(false);
|
||||
replay(createWindow, listWindow, editWindow, workRelationshipsWindow, workerModel);
|
||||
// actions
|
||||
workerCRUDController.goToCreateForm();
|
||||
workerCRUDController.cancel();
|
||||
|
|
@ -107,8 +112,8 @@ public class WorkerCRUDControllerTest {
|
|||
.anyTimes();
|
||||
workerModel.save();
|
||||
messagesForUser.showMessage(same(Level.INFO), isA(String.class));
|
||||
replay(createWindow, listWindow, editWindow, workerModel,
|
||||
messagesForUser);
|
||||
replay(createWindow, listWindow, editWindow, workRelationshipsWindow,
|
||||
workerModel, messagesForUser);
|
||||
// perform actions
|
||||
List<Worker> workers = workerCRUDController.getWorkers();
|
||||
assertEquals(workersToReturn, workers);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue