ItEr50S13AdaptacionServiciosRESTItEr49S18 : Refactoring the create way a work report line.
It is need a work report to create a work report line , and now the work report line does not change its work report.
This commit is contained in:
parent
fce8818b41
commit
5024b7c4bc
7 changed files with 38 additions and 29 deletions
|
|
@ -144,7 +144,6 @@ public class WorkReport extends IntegrationEntity {
|
|||
|
||||
public void addWorkReportLine(WorkReportLine workReportLine) {
|
||||
workReportLines.add(workReportLine);
|
||||
workReportLine.setWorkReport(this);
|
||||
}
|
||||
|
||||
public void removeWorkReportLine(WorkReportLine workReportLine) {
|
||||
|
|
|
|||
|
|
@ -56,13 +56,14 @@ public class WorkReportLine extends IntegrationEntity implements Comparable {
|
|||
|
||||
public static final String HOURS = "numHours";
|
||||
|
||||
public static WorkReportLine create() {
|
||||
return create(new WorkReportLine());
|
||||
public static WorkReportLine create(WorkReport workReport) {
|
||||
return create(new WorkReportLine(workReport));
|
||||
}
|
||||
|
||||
public static WorkReportLine create(Integer numHours, Resource resource,
|
||||
OrderElement orderElement) {
|
||||
return create(new WorkReportLine(numHours, resource, orderElement));
|
||||
OrderElement orderElement, WorkReport workReport) {
|
||||
return create(new WorkReportLine(numHours, resource, orderElement,
|
||||
workReport));
|
||||
}
|
||||
|
||||
private Integer numHours;
|
||||
|
|
@ -89,11 +90,15 @@ public class WorkReportLine extends IntegrationEntity implements Comparable {
|
|||
* Constructor for hibernate. Do not use!
|
||||
*/
|
||||
public WorkReportLine() {
|
||||
}
|
||||
|
||||
public WorkReportLine(WorkReport workReport) {
|
||||
this.setWorkReport(workReport);
|
||||
}
|
||||
|
||||
private WorkReportLine(Integer numHours, Resource resource,
|
||||
OrderElement orderElement) {
|
||||
OrderElement orderElement, WorkReport workReport) {
|
||||
this(workReport);
|
||||
this.numHours = numHours;
|
||||
this.resource = resource;
|
||||
this.orderElement = orderElement;
|
||||
|
|
@ -199,7 +204,7 @@ public class WorkReportLine extends IntegrationEntity implements Comparable {
|
|||
return workReport;
|
||||
}
|
||||
|
||||
public void setWorkReport(WorkReport workReport) {
|
||||
private void setWorkReport(WorkReport workReport) {
|
||||
this.workReport = workReport;
|
||||
|
||||
// update and copy the fields and label for each line
|
||||
|
|
|
|||
|
|
@ -78,8 +78,7 @@ public abstract class AbstractWorkReportTest {
|
|||
WorkReport workReport = createValidWorkReport();
|
||||
workReportDAO.save(workReport);
|
||||
|
||||
WorkReportLine workReportLine = WorkReportLine.create();
|
||||
workReportLine.setWorkReport(workReport);
|
||||
WorkReportLine workReportLine = WorkReportLine.create(workReport);
|
||||
workReport.addWorkReportLine(workReportLine);
|
||||
workReportLine.setDate(new Date());
|
||||
workReportLine.setNumHours(100);
|
||||
|
|
|
|||
|
|
@ -65,8 +65,8 @@ public class WorkReportTest {
|
|||
.create("Firstname", "Surname", "NIF-" + UUID.randomUUID());
|
||||
}
|
||||
|
||||
private WorkReportLine givenBasicWorkReportLine() {
|
||||
WorkReportLine workReportLine = WorkReportLine.create();
|
||||
private WorkReportLine givenBasicWorkReportLine(WorkReport workReport) {
|
||||
WorkReportLine workReportLine = WorkReportLine.create(workReport);
|
||||
workReportLine.setCode("work-report-line-code-" + UUID.randomUUID());
|
||||
|
||||
return workReportLine;
|
||||
|
|
@ -166,7 +166,7 @@ public class WorkReportTest {
|
|||
WorkReport workReport = givenBasicWorkReport();
|
||||
workReport.setWorkReportType(workReportType);
|
||||
|
||||
WorkReportLine workReportLine1 = givenBasicWorkReportLine();
|
||||
WorkReportLine workReportLine1 = givenBasicWorkReportLine(workReport);
|
||||
workReport.addWorkReportLine(workReportLine1);
|
||||
|
||||
workReport.setDate(new Date());
|
||||
|
|
@ -177,7 +177,7 @@ public class WorkReportTest {
|
|||
assertNotNull(workReportLine1.getOrderElement());
|
||||
assertNotNull(workReportLine1.getResource());
|
||||
|
||||
WorkReportLine workReportLine2 = givenBasicWorkReportLine();
|
||||
WorkReportLine workReportLine2 = givenBasicWorkReportLine(workReport);
|
||||
workReport.addWorkReportLine(workReportLine2);
|
||||
|
||||
assertNotNull(workReportLine2.getDate());
|
||||
|
|
@ -201,7 +201,7 @@ public class WorkReportTest {
|
|||
.setHoursManagement(HoursManagementEnum.HOURS_CALCULATED_BY_CLOCK);
|
||||
|
||||
WorkReport workReport = WorkReport.create(workReportType);
|
||||
WorkReportLine workReportLine = givenBasicWorkReportLine();
|
||||
WorkReportLine workReportLine = givenBasicWorkReportLine(workReport);
|
||||
|
||||
workReport.addWorkReportLine(workReportLine);
|
||||
|
||||
|
|
@ -223,22 +223,23 @@ public class WorkReportTest {
|
|||
|
||||
@Test
|
||||
public void checkHoursCalculatedByClock2() {
|
||||
WorkReportLine workReportLine = givenBasicWorkReportLine();
|
||||
workReportLine.setNumHours(10);
|
||||
|
||||
LocalTime start = new LocalTime(8, 0);
|
||||
LocalTime end = start.plusHours(8);
|
||||
|
||||
workReportLine.setClockStart(start);
|
||||
workReportLine.setClockFinish(end);
|
||||
|
||||
WorkReportType workReportType = givenBasicWorkReportType();
|
||||
workReportType
|
||||
.setHoursManagement(HoursManagementEnum.HOURS_CALCULATED_BY_CLOCK);
|
||||
|
||||
WorkReport workReport = WorkReport.create(workReportType);
|
||||
|
||||
WorkReportLine workReportLine = givenBasicWorkReportLine(workReport);
|
||||
workReport.addWorkReportLine(workReportLine);
|
||||
|
||||
workReportLine.setNumHours(10);
|
||||
LocalTime start = new LocalTime(8, 0);
|
||||
LocalTime end = start.plusHours(8);
|
||||
|
||||
workReportLine.setClockStart(start);
|
||||
workReportLine.setClockFinish(end);
|
||||
|
||||
assertThat(workReportLine.getNumHours(), equalTo(8));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -784,7 +784,7 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
|
|||
* @param rows
|
||||
*/
|
||||
public void addWorkReportLine() {
|
||||
WorkReportLine workReportLine = workReportModel.addWorkReportLine();
|
||||
workReportModel.addWorkReportLine();
|
||||
reloadWorkReportLines();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -330,9 +330,12 @@ public class WorkReportModel implements IWorkReportModel {
|
|||
|
||||
@Override
|
||||
public WorkReportLine addWorkReportLine() {
|
||||
WorkReportLine workReportLine = WorkReportLine.create();
|
||||
workReport.addWorkReportLine(workReportLine);
|
||||
return workReportLine;
|
||||
if (workReport != null) {
|
||||
WorkReportLine workReportLine = WorkReportLine.create(workReport);
|
||||
workReport.addWorkReportLine(workReportLine);
|
||||
return workReportLine;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ public final class WorkReportConverter {
|
|||
workReport.setWorkReportType(workReportType);
|
||||
|
||||
for (WorkReportLineDTO workReportLineDTO : workReportDTO.workReportLines) {
|
||||
workReport.addWorkReportLine(toEntity(workReportLineDTO));
|
||||
workReport
|
||||
.addWorkReportLine(toEntity(workReportLineDTO, workReport));
|
||||
}
|
||||
|
||||
// Optional fields
|
||||
|
|
@ -88,9 +89,10 @@ public final class WorkReportConverter {
|
|||
return workReport;
|
||||
}
|
||||
|
||||
private static WorkReportLine toEntity(WorkReportLineDTO workReportLineDTO)
|
||||
private static WorkReportLine toEntity(WorkReportLineDTO workReportLineDTO,
|
||||
WorkReport workReport)
|
||||
throws InstanceNotFoundException {
|
||||
WorkReportLine workReportLine = WorkReportLine.create();
|
||||
WorkReportLine workReportLine = WorkReportLine.create(workReport);
|
||||
|
||||
// Mandatory fields
|
||||
workReportLine.setNumHours(workReportLineDTO.numHours);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue