Author: ymartel Date: 2014-08-12 10:11:13 +0200 (Tue, 12 Aug 2014) New Revision: 433 Url: http://forge.chorem.org/projects/chorem/repository/revisions/433 Log: fix some NPE with new ExpenseAccount Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountBean.java trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountEntryBean.java Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java 2014-08-11 12:13:23 UTC (rev 432) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java 2014-08-12 08:11:13 UTC (rev 433) @@ -27,6 +27,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -150,7 +151,14 @@ expenseAccountWikitty.setBeginDate(new Date(expenseAccountBean.getStartDate())); expenseAccountWikitty.setEndDate(new Date(expenseAccountBean.getEndDate())); - Set<String> missingAccountEntryIds = Sets.newHashSet(expenseAccountWikitty.getExpenseAccountEntry()); + Set<String> existingExpenseEntryIds = expenseAccountWikitty.getExpenseAccountEntry(); + Set<String> missingAccountEntryIds; + if (existingExpenseEntryIds != null) { + missingAccountEntryIds = Sets.newHashSet(existingExpenseEntryIds); + } else { + missingAccountEntryIds = new HashSet<>(); + } + expenseAccountWikitty.clearExpenseAccountEntry(); //manage each Expense Account Entry : try to find them or create new one @@ -201,8 +209,6 @@ public Render findExpenseAccount(ChoremClient client, String expenseAccountId) { ExpenseAccount expenseAccount = client.restore(ExpenseAccount.class, expenseAccountId); - Set<String> expenseAccountEntryIds = expenseAccount.getExpenseAccountEntry(); - Set<ExpenseAccountEntry> expenseAccountEntries = client.restore(ExpenseAccountEntry.class, expenseAccountEntryIds); if (expenseAccount == null) { expenseAccount = new ExpenseAccountImpl(); @@ -226,10 +232,14 @@ expenseAccountBean.setEndDate(expenseAccount.getEndDate()); expenseAccountBean.setEndDate(expenseAccount.getEndDate()); Set<ExpenseAccountEntry> expenseAccountEntries = expenseAccount.getExpenseAccountEntry(false); - for (ExpenseAccountEntry expenseAccountEntry : expenseAccountEntries) { - if (expenseAccountEntry != null) { - ExpenseAccountEntryBean expenseAccountEntryBean = TRANSFORM_EXPENSE_ACCOUNT_ENTRY_TO_BEAN.apply(expenseAccountEntry); - expenseAccountBean.addExpenseAccountEntry(expenseAccountEntryBean); + if (expenseAccountEntries == null) { + expenseAccountBean.setExpenseAccountEntries(new HashSet<ExpenseAccountEntryBean>()); + } else { + for (ExpenseAccountEntry expenseAccountEntry : expenseAccountEntries) { + if (expenseAccountEntry != null) { + ExpenseAccountEntryBean expenseAccountEntryBean = TRANSFORM_EXPENSE_ACCOUNT_ENTRY_TO_BEAN.apply(expenseAccountEntry); + expenseAccountBean.addExpenseAccountEntry(expenseAccountEntryBean); + } } } return expenseAccountBean; Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountBean.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountBean.java 2014-08-11 12:13:23 UTC (rev 432) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountBean.java 2014-08-12 08:11:13 UTC (rev 433) @@ -75,7 +75,9 @@ } public void setStartDate(Date startDate) { - this.startDate = startDate.getTime(); + if (startDate != null) { + this.startDate = startDate.getTime(); + } } public long getEndDate() { @@ -87,7 +89,9 @@ } public void setEndDate(Date endDate) { - this.endDate = endDate.getTime(); + if (endDate != null) { + this.endDate = endDate.getTime(); + } } public Set<ExpenseAccountEntryBean> getExpenseAccountEntries() { Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountEntryBean.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountEntryBean.java 2014-08-11 12:13:23 UTC (rev 432) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountEntryBean.java 2014-08-12 08:11:13 UTC (rev 433) @@ -77,7 +77,9 @@ } public void setEmittedDate(Date emittedDate) { - this.emittedDate = emittedDate.getTime(); + if (emittedDate != null) { + this.emittedDate = emittedDate.getTime(); + } } public long getPaymentDate() { @@ -89,7 +91,9 @@ } public void setPaymentDate(Date paymentDate) { - this.paymentDate = paymentDate.getTime(); + if (paymentDate != null) { + this.paymentDate = paymentDate.getTime(); + } } public String getDescription() {