change the properties with type Date to LocalDate in the ExpenseSheet and
ExpenseSheetLine classes. FEA: ItEr76S22ExpenseTrackingSystem
This commit is contained in:
parent
5fb7dedda8
commit
6e2e51652d
10 changed files with 145 additions and 43 deletions
|
|
@ -21,7 +21,6 @@ package org.libreplan.business.expensesheet.entities;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
|
|
@ -30,6 +29,7 @@ import org.hibernate.validator.Min;
|
|||
import org.hibernate.validator.NotEmpty;
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.hibernate.validator.Valid;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.libreplan.business.common.IntegrationEntity;
|
||||
import org.libreplan.business.common.Registry;
|
||||
import org.libreplan.business.common.entities.EntitySequence;
|
||||
|
|
@ -42,9 +42,9 @@ import org.libreplan.business.expensesheet.daos.IExpenseSheetDAO;
|
|||
*/
|
||||
public class ExpenseSheet extends IntegrationEntity {
|
||||
|
||||
private Date firstExpense;
|
||||
private LocalDate firstExpense;
|
||||
|
||||
private Date lastExpense;
|
||||
private LocalDate lastExpense;
|
||||
|
||||
private BigDecimal total;
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ public class ExpenseSheet extends IntegrationEntity {
|
|||
protected ExpenseSheet() {
|
||||
}
|
||||
|
||||
protected ExpenseSheet(Date firstExpense, Date lastExpense, BigDecimal total) {
|
||||
protected ExpenseSheet(LocalDate firstExpense, LocalDate lastExpense, BigDecimal total) {
|
||||
this.setFirstExpense(firstExpense);
|
||||
this.setLastExpense(lastExpense);
|
||||
this.setTotal(total);
|
||||
|
|
@ -72,7 +72,8 @@ public class ExpenseSheet extends IntegrationEntity {
|
|||
return create(new ExpenseSheet());
|
||||
}
|
||||
|
||||
public static ExpenseSheet create(Date firstExpense, Date lastExpense, BigDecimal total) {
|
||||
public static ExpenseSheet create(LocalDate firstExpense, LocalDate lastExpense,
|
||||
BigDecimal total) {
|
||||
return create(new ExpenseSheet(firstExpense, lastExpense, total));
|
||||
}
|
||||
|
||||
|
|
@ -81,19 +82,19 @@ public class ExpenseSheet extends IntegrationEntity {
|
|||
return Registry.getExpenseSheetDAO();
|
||||
}
|
||||
|
||||
protected void setFirstExpense(Date firstExpense) {
|
||||
protected void setFirstExpense(LocalDate firstExpense) {
|
||||
this.firstExpense = firstExpense;
|
||||
}
|
||||
|
||||
public Date getFirstExpense() {
|
||||
public LocalDate getFirstExpense() {
|
||||
return firstExpense;
|
||||
}
|
||||
|
||||
protected void setLastExpense(Date lastExpense) {
|
||||
protected void setLastExpense(LocalDate lastExpense) {
|
||||
this.lastExpense = lastExpense;
|
||||
}
|
||||
|
||||
public Date getLastExpense() {
|
||||
public LocalDate getLastExpense() {
|
||||
return lastExpense;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@
|
|||
package org.libreplan.business.expensesheet.entities;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
import org.hibernate.validator.Min;
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.libreplan.business.common.IntegrationEntity;
|
||||
import org.libreplan.business.common.Registry;
|
||||
import org.libreplan.business.common.daos.IIntegrationEntityDAO;
|
||||
|
|
@ -41,7 +41,7 @@ public class ExpenseSheetLine extends IntegrationEntity {
|
|||
|
||||
private String concept;
|
||||
|
||||
private Date date;
|
||||
private LocalDate date;
|
||||
|
||||
private OrderElement orderElement;
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ public class ExpenseSheetLine extends IntegrationEntity {
|
|||
|
||||
}
|
||||
|
||||
private ExpenseSheetLine(BigDecimal value, String concept, Date date,
|
||||
private ExpenseSheetLine(BigDecimal value, String concept, LocalDate date,
|
||||
OrderElement orderElement) {
|
||||
this.orderElement = orderElement;
|
||||
this.concept = concept;
|
||||
|
|
@ -64,7 +64,7 @@ public class ExpenseSheetLine extends IntegrationEntity {
|
|||
this.setDate(date);
|
||||
}
|
||||
|
||||
public static ExpenseSheetLine create(BigDecimal value, String concept, Date date,
|
||||
public static ExpenseSheetLine create(BigDecimal value, String concept, LocalDate date,
|
||||
OrderElement orderElement) {
|
||||
return create(new ExpenseSheetLine(value, concept, date, orderElement));
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ public class ExpenseSheetLine extends IntegrationEntity {
|
|||
return Registry.getExpenseSheetLineDAO();
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
public void setDate(LocalDate date) {
|
||||
boolean different = isDifferent(date);
|
||||
this.date = date;
|
||||
if (this.expenseSheet != null && different) {
|
||||
|
|
@ -133,7 +133,7 @@ public class ExpenseSheetLine extends IntegrationEntity {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isDifferent(Date date) {
|
||||
private boolean isDifferent(LocalDate date) {
|
||||
if (this.date == null && date == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -144,7 +144,7 @@ public class ExpenseSheetLine extends IntegrationEntity {
|
|||
}
|
||||
|
||||
@NotNull(message = "date not specified")
|
||||
public Date getDate() {
|
||||
public LocalDate getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,23 @@ public class ExpenseSheetLineComparator implements Comparator<ExpenseSheetLine>
|
|||
|
||||
@Override
|
||||
public int compare(ExpenseSheetLine arg0, ExpenseSheetLine arg1) {
|
||||
if (arg0.getDate() == arg1.getDate()) {
|
||||
if ((arg0.getDate() == null) && (arg1.getDate() == null)) {
|
||||
return compareCode(arg0, arg1);
|
||||
}
|
||||
if (arg0.getDate() == null) {
|
||||
return -1;
|
||||
}
|
||||
if (arg1.getDate() == null) {
|
||||
return 1;
|
||||
}
|
||||
if (arg1.getDate().compareTo(arg0.getDate()) == 0) {
|
||||
return compareCode(arg0, arg1);
|
||||
}
|
||||
return arg1.getDate().compareTo(arg0.getDate());
|
||||
}
|
||||
|
||||
private int compareCode(ExpenseSheetLine arg0, ExpenseSheetLine arg1) {
|
||||
if ((arg0.getCode() == null) && (arg1.getCode() == null)) {
|
||||
return 0;
|
||||
}
|
||||
if (arg0.getDate() == null) {
|
||||
|
|
@ -39,6 +55,6 @@ public class ExpenseSheetLineComparator implements Comparator<ExpenseSheetLine>
|
|||
if (arg1.getDate() == null) {
|
||||
return 1;
|
||||
}
|
||||
return arg1.getDate().compareTo(arg0.getDate());
|
||||
return arg1.getCode().compareTo(arg0.getCode());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -226,4 +226,15 @@
|
|||
columnDataType="BOOLEAN" />
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="modify-columns-type-in-expense-sheet-to-date" author="smontes">
|
||||
<comment>modify columns type in expense sheet to date</comment>
|
||||
<modifyDataType tableName="expense_sheet" columnName="first_expense" newDataType="DATE"/>
|
||||
<modifyDataType tableName="expense_sheet" columnName="last_expense" newDataType="DATE"/>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="modify-columns-type-in-expense-sheet-line-to-date" author="smontes">
|
||||
<comment>modify columns type in expense sheet line to date</comment>
|
||||
<modifyDataType tableName="expense_sheet_line" columnName="date" newDataType="DATE"/>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@
|
|||
|
||||
<property name="value" access="field" column="value" />
|
||||
<property name="concept" access="field" column="concept" />
|
||||
<property name="date" access="field" column="date" />
|
||||
<property name="date" access="field" column="date"
|
||||
type="org.joda.time.contrib.hibernate.PersistentLocalDate" />
|
||||
|
||||
<many-to-one name="orderElement" column="order_element_id"
|
||||
class="org.libreplan.business.orders.entities.OrderElement" />
|
||||
|
|
@ -46,9 +47,11 @@
|
|||
<property name="codeAutogenerated" not-null="true"
|
||||
column="code_autogenerated" />
|
||||
|
||||
<property name="firstExpense" access="field" column="first_expense" />
|
||||
<property name="firstExpense" access="field" column="first_expense"
|
||||
type="org.joda.time.contrib.hibernate.PersistentLocalDate" />
|
||||
|
||||
<property name="lastExpense" access="field" column="last_expense" />
|
||||
<property name="lastExpense" access="field" column="last_expense"
|
||||
type="org.joda.time.contrib.hibernate.PersistentLocalDate" />
|
||||
|
||||
<property name="total" access="field" column="total" />
|
||||
|
||||
|
|
|
|||
|
|
@ -178,8 +178,8 @@ public class ExpenseSheetTestDAO {
|
|||
OrderElement orderElement = null;
|
||||
|
||||
// a expense sheet with valid value,date but without order element.
|
||||
ExpenseSheetLine line1 = ExpenseSheetLine.create(BigDecimal.ZERO, "concept", new Date(),
|
||||
orderElement);
|
||||
ExpenseSheetLine line1 = ExpenseSheetLine.create(BigDecimal.ZERO, "concept",
|
||||
new LocalDate(), orderElement);
|
||||
|
||||
line1.setExpenseSheet(expense);
|
||||
expense.add(line1);
|
||||
|
|
@ -199,7 +199,7 @@ public class ExpenseSheetTestDAO {
|
|||
OrderElement orderElement = this.givenOrderElement("order-element-2");
|
||||
|
||||
// a expense sheet with valid date and order element, but invalid value.
|
||||
ExpenseSheetLine line1 = ExpenseSheetLine.create(null, "concept", new Date(),
|
||||
ExpenseSheetLine line1 = ExpenseSheetLine.create(null, "concept", new LocalDate(),
|
||||
orderElement);
|
||||
|
||||
// add the line to the expense sheet
|
||||
|
|
@ -220,8 +220,8 @@ public class ExpenseSheetTestDAO {
|
|||
} catch (ValidationException e) {
|
||||
}
|
||||
|
||||
ExpenseSheetLine line2 = ExpenseSheetLine.create(BigDecimal.TEN, "concept", new Date(),
|
||||
orderElement);
|
||||
ExpenseSheetLine line2 = ExpenseSheetLine.create(BigDecimal.TEN, "concept",
|
||||
new LocalDate(), orderElement);
|
||||
|
||||
// add other line to the expense sheet
|
||||
line2.setExpenseSheet(expense);
|
||||
|
|
@ -267,14 +267,14 @@ public class ExpenseSheetTestDAO {
|
|||
} catch (ValidationException e) {
|
||||
}
|
||||
|
||||
Date today = new Date();
|
||||
LocalDate today = new LocalDate();
|
||||
line1.setDate(today);
|
||||
|
||||
assertThat(expense.getFirstExpense(), equalTo(today));
|
||||
assertThat(expense.getLastExpense(), equalTo(today));
|
||||
|
||||
// add other line with other date
|
||||
Date tomorrow = new LocalDate().plusDays(1).toDateTimeAtStartOfDay().toDate();
|
||||
LocalDate tomorrow = new LocalDate().plusDays(1);
|
||||
ExpenseSheetLine line2 = ExpenseSheetLine.create(BigDecimal.ONE, "concept", tomorrow,
|
||||
orderElement);
|
||||
line2.setExpenseSheet(expense);
|
||||
|
|
@ -305,7 +305,7 @@ public class ExpenseSheetTestDAO {
|
|||
Worker worker = givenSavedValidWorker();
|
||||
|
||||
// add line 1 with a resource
|
||||
Date today = new Date();
|
||||
LocalDate today = new LocalDate();
|
||||
ExpenseSheetLine line1 = ExpenseSheetLine.create(BigDecimal.ONE, "concept 1", today,
|
||||
orderElement);
|
||||
line1.setResource(worker);
|
||||
|
|
@ -313,7 +313,7 @@ public class ExpenseSheetTestDAO {
|
|||
expense.add(line1);
|
||||
|
||||
// add line 2 without resource
|
||||
Date tomorrow = new LocalDate().plusDays(1).toDateTimeAtStartOfDay().toDate();
|
||||
LocalDate tomorrow = new LocalDate().plusDays(1);
|
||||
ExpenseSheetLine line2 = ExpenseSheetLine.create(BigDecimal.ONE, "concept 2", tomorrow,
|
||||
orderElement);
|
||||
line2.setExpenseSheet(expense);
|
||||
|
|
@ -411,7 +411,7 @@ public class ExpenseSheetTestDAO {
|
|||
expense.setCode(code);
|
||||
|
||||
// add line 1
|
||||
Date today = new Date();
|
||||
LocalDate today = new LocalDate();
|
||||
ExpenseSheetLine line1 = ExpenseSheetLine.create(BigDecimal.ONE, "concept 1", today,
|
||||
orderElement);
|
||||
line1.setExpenseSheet(expense);
|
||||
|
|
@ -491,7 +491,6 @@ public class ExpenseSheetTestDAO {
|
|||
assertThat(expenseSheetDAO.getAll().size(), equalTo(previousExpenses + 1));
|
||||
assertThat(expenseSheetLineDAO.findAll().size(), equalTo(previousExpenseLines + 1));
|
||||
|
||||
|
||||
expenseSheetDAO.remove(expense.getId());
|
||||
expenseSheetDAO.flush();
|
||||
|
||||
|
|
@ -515,7 +514,7 @@ public class ExpenseSheetTestDAO {
|
|||
Worker worker = givenSavedValidWorker();
|
||||
|
||||
// add line 1 with a resource
|
||||
Date today = new Date();
|
||||
LocalDate today = new LocalDate();
|
||||
ExpenseSheetLine line1 = ExpenseSheetLine.create(BigDecimal.ONE, "concept 1", today,
|
||||
orderElement);
|
||||
line1.setResource(worker);
|
||||
|
|
@ -523,7 +522,7 @@ public class ExpenseSheetTestDAO {
|
|||
expense.add(line1);
|
||||
|
||||
// add line 2 without resource
|
||||
Date tomorrow = new LocalDate().plusDays(1).toDateTimeAtStartOfDay().toDate();
|
||||
LocalDate tomorrow = new LocalDate().plusDays(1);
|
||||
ExpenseSheetLine line2 = ExpenseSheetLine.create(BigDecimal.ONE, "concept 2", tomorrow,
|
||||
orderElement);
|
||||
line2.setCode("code-line-2");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* Copyright (C) 2012 WirelessGalicia, S.L.
|
||||
*
|
||||
* 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.libreplan.web.common.typeconverters;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zkplus.databind.TypeConverter;
|
||||
|
||||
/**
|
||||
* Converter for the type java.util.LocalDate
|
||||
*
|
||||
* @author Susana Montes Pedreira smontes@wirelessgalicia.com
|
||||
*
|
||||
*/
|
||||
public class LocalDateConverter implements TypeConverter {
|
||||
|
||||
@Override
|
||||
public Object coerceToBean(Object arg0, Component arg1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object coerceToUi(Object object, Component component) {
|
||||
LocalDate localDate = (LocalDate) object;
|
||||
Date date = localDate != null ? localDate.toDateTimeAtStartOfDay().toDate() : null;
|
||||
return date != null ? (new SimpleDateFormat("dd/MM/yyyy")).format(date)
|
||||
: new String("");
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +28,7 @@ import java.util.List;
|
|||
import java.util.SortedSet;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.libreplan.business.expensesheet.entities.ExpenseSheet;
|
||||
import org.libreplan.business.expensesheet.entities.ExpenseSheetLine;
|
||||
import org.libreplan.business.orders.entities.Order;
|
||||
|
|
@ -372,7 +373,7 @@ public class ExpenseSheetCRUDController extends GenericForwardComposer {
|
|||
|
||||
private String getExpenseSheetLineName(ExpenseSheetLine expenseSheetLine) {
|
||||
if (expenseSheetLine != null) {
|
||||
Date date = expenseSheetLine.getDate();
|
||||
LocalDate date = expenseSheetLine.getDate();
|
||||
OrderElement task = expenseSheetLine.getOrderElement();
|
||||
if (date != null && task != null) {
|
||||
return _("expense line of the ") + task.getName() + " - " + date;
|
||||
|
|
@ -486,7 +487,9 @@ public class ExpenseSheetCRUDController extends GenericForwardComposer {
|
|||
@Override
|
||||
public Date get() {
|
||||
if (expenseSheetLine != null) {
|
||||
return expenseSheetLine.getDate();
|
||||
if (expenseSheetLine.getDate() != null) {
|
||||
return expenseSheetLine.getDate().toDateTimeAtStartOfDay().toDate();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -496,7 +499,11 @@ public class ExpenseSheetCRUDController extends GenericForwardComposer {
|
|||
@Override
|
||||
public void set(Date value) {
|
||||
if (expenseSheetLine != null) {
|
||||
expenseSheetLine.setDate(value);
|
||||
LocalDate newDate = null;
|
||||
if (value != null) {
|
||||
newDate = LocalDate.fromDateFields(value);
|
||||
}
|
||||
expenseSheetLine.setDate(newDate);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -688,4 +695,19 @@ public class ExpenseSheetCRUDController extends GenericForwardComposer {
|
|||
};
|
||||
}
|
||||
|
||||
public Date getExpenseSheetLineDate() {
|
||||
if (expenseSheetModel.getExpenseSheetLineDTO() != null) {
|
||||
return (expenseSheetModel.getExpenseSheetLineDTO().getDate() != null) ? expenseSheetModel
|
||||
.getExpenseSheetLineDTO().getDate().toDateTimeAtStartOfDay().toDate()
|
||||
: null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setExpenseSheetLineDate(Date date) {
|
||||
if (expenseSheetModel.getExpenseSheetLineDTO() != null) {
|
||||
expenseSheetModel.getExpenseSheetLineDTO().setDate(LocalDate.fromDateFields(date));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ package org.libreplan.web.expensesheet;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
|
@ -30,6 +29,7 @@ import java.util.TreeSet;
|
|||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.libreplan.business.common.IntegrationEntity;
|
||||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||
import org.libreplan.business.common.entities.EntityNameEnum;
|
||||
|
|
@ -176,8 +176,8 @@ public class ExpenseSheetModel extends IntegrationEntityModel implements IExpens
|
|||
}
|
||||
|
||||
private void resetExpenseSheetLineDTO() {
|
||||
this.expenseSheetLineDTO = ExpenseSheetLine.create(new BigDecimal(0), "", new Date(), null);
|
||||
this.expenseSheetLineDTO.setCode("");
|
||||
this.expenseSheetLineDTO = ExpenseSheetLine.create(new BigDecimal(0), "", new LocalDate(),
|
||||
null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -62,8 +62,8 @@
|
|||
</columns>
|
||||
<rows>
|
||||
<row self="@{each='expensesheet'}" value="@{expensesheet}" onClick="controller.goToEditForm(self.value);">
|
||||
<label value="@{expensesheet.firstExpense, converter='org.libreplan.web.common.typeconverters.DateConverter'}" />
|
||||
<label value="@{expensesheet.lastExpense, converter='org.libreplan.web.common.typeconverters.DateConverter'}"/>
|
||||
<label value="@{expensesheet.firstExpense, converter='org.libreplan.web.common.typeconverters.LocalDateConverter'}" />
|
||||
<label value="@{expensesheet.lastExpense, converter='org.libreplan.web.common.typeconverters.LocalDateConverter'}"/>
|
||||
<label value="@{expensesheet.total}" />
|
||||
<label value="@{expensesheet.code}" />
|
||||
<label value="@{expensesheet.description}" />
|
||||
|
|
@ -121,7 +121,8 @@
|
|||
</hbox>
|
||||
<hbox>
|
||||
<label value="${i18n:_('Expense date')}" />
|
||||
<datebox id="dateboxExpenseDate" width="150px" value="@{controller.expenseSheetLineDTO.date}"
|
||||
<datebox id="dateboxExpenseDate" width="150px"
|
||||
value="@{controller.expenseSheetLineDate}"
|
||||
constraint="no empty:${i18n:_('cannot be null or empty')}"/>
|
||||
</hbox>
|
||||
</vbox>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue