This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository lima. See http://git.chorem.org/lima.git commit 89caf6e9bb57e0465ab27d7b5554e749ac79030b Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 8 09:58:55 2015 +0200 refs #1218: Plan BCR : exception à la deuxième modification d'un regrouppement --- .../business/api/FinancialStatementService.java | 4 +- .../ejb/FinancialStatementServiceImpl.java | 54 +++++-------- .../lima/business/ejb/ImportServiceImpl.java | 17 ++-- .../FinancialStatementChartTreeTableModel.java | 94 ++++++++++++---------- .../FinancialStatementChartViewHandler.java | 29 ++++--- 5 files changed, 96 insertions(+), 102 deletions(-) diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialStatementService.java b/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialStatementService.java index af30ffb..a24f032 100644 --- a/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialStatementService.java +++ b/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialStatementService.java @@ -40,12 +40,12 @@ public interface FinancialStatementService { */ FinancialStatement newFinancialStatement(); - void createMasterFinacialStatements(FinancialStatement masterFinancialStatements); + FinancialStatement createMasterFinacialStatements(FinancialStatement masterFinancialStatements); FinancialStatement createFinancialStatement(FinancialStatement masterFinancialStatement, FinancialStatement financialStatement) throws AlreadyExistFinancialStatement, NotAllowedLabelException; - void updateFinancialStatement(FinancialStatement financialStatement); + FinancialStatement updateFinancialStatement(FinancialStatement financialStatement); void removeFinancialStatement(FinancialStatement financialStatement); diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java index d98e599..4fb4cb7 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java @@ -23,6 +23,7 @@ package org.chorem.lima.business.ejb; import com.google.common.base.Function; +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import org.apache.commons.lang3.StringUtils; @@ -46,8 +47,6 @@ import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountTopiaDao; import org.chorem.lima.entity.FinancialStatement; import org.chorem.lima.entity.FinancialStatementTopiaDao; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderFactory; import javax.ejb.EJB; import javax.ejb.Remote; @@ -97,25 +96,6 @@ public class FinancialStatementServiceImpl extends AbstractLimaService implement } } - protected void addFinancialStatementToMaster(FinancialStatement masterFinancialStatement, - FinancialStatement financialStatement) { - if (masterFinancialStatement != null) { - FinancialStatementTopiaDao financialStatementTopiaDao = getDaoHelper().getFinancialStatementDao(); - - masterFinancialStatement.addSubFinancialStatements(financialStatement); - - if (masterFinancialStatement.isPersisted()) { - // update the persisted entity to avoid NonUniqueObjectException: A different object with the same identifier value was already associated with the session - FinancialStatement financialStatementToUpdate = financialStatementTopiaDao.forTopiaIdEquals(masterFinancialStatement.getTopiaId()).findUnique(); - Binder<FinancialStatement, FinancialStatement> binder = BinderFactory.newBinder(FinancialStatement.class, FinancialStatement.class); - binder.copy(masterFinancialStatement, financialStatementToUpdate); - financialStatementTopiaDao.update(financialStatementToUpdate); - } else { - financialStatementTopiaDao.create(masterFinancialStatement); - } - } - } - @Override public FinancialStatement newFinancialStatement() { FinancialStatementTopiaDao financialStatementTopiaDao = getDaoHelper().getFinancialStatementDao(); @@ -124,29 +104,32 @@ public class FinancialStatementServiceImpl extends AbstractLimaService implement } @Override - public void createMasterFinacialStatements(FinancialStatement masterFinancialStatements) { + public FinancialStatement createMasterFinacialStatements(FinancialStatement masterFinancialStatements) { FinancialStatementTopiaDao financialStatementTopiaDao = getDaoHelper().getFinancialStatementDao(); - financialStatementTopiaDao.create(masterFinancialStatements); + FinancialStatement result = financialStatementTopiaDao.create(masterFinancialStatements); + return result; } @Override - public FinancialStatement createFinancialStatement(FinancialStatement masterFinancialStatement, + public FinancialStatement createFinancialStatement(FinancialStatement parentFinancialStatement, FinancialStatement financialStatement) throws AlreadyExistFinancialStatement, NotAllowedLabelException { - validateNewFinancialStatement(masterFinancialStatement, financialStatement); + validateNewFinancialStatement(parentFinancialStatement, financialStatement); + Preconditions.checkState(parentFinancialStatement.isPersisted(), "parents statement must be persited"); + Preconditions.checkState(! financialStatement.isPersisted(), " statement to create must be not persited"); FinancialStatementTopiaDao financialStatementTopiaDao = getDaoHelper().getFinancialStatementDao(); - FinancialStatement result; - if (!financialStatement.isPersisted()) { - result = financialStatementTopiaDao.create(financialStatement); - } else { - result = financialStatement; - } + // refresh parent financialstatement + parentFinancialStatement = financialStatementTopiaDao.forTopiaIdEquals(parentFinancialStatement.getTopiaId()).findUnique(); - addFinancialStatementToMaster(masterFinancialStatement, result); + financialStatement = financialStatementTopiaDao.create(financialStatement); - return result; + parentFinancialStatement.addSubFinancialStatements(financialStatement); + + financialStatementTopiaDao.update(parentFinancialStatement); + + return financialStatement; } @Override @@ -192,13 +175,14 @@ public class FinancialStatementServiceImpl extends AbstractLimaService implement } @Override - public void updateFinancialStatement(FinancialStatement financialStatement) { + public FinancialStatement updateFinancialStatement(FinancialStatement financialStatement) { // TopiaDao FinancialStatementTopiaDao financialStatementHeaderTopiaDao = getDaoHelper().getFinancialStatementDao(); //update - financialStatementHeaderTopiaDao.update(financialStatement); + financialStatement = financialStatementHeaderTopiaDao.update(financialStatement); + return financialStatement; } diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java index 188cd3f..b9d34b6 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java @@ -480,7 +480,7 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ if (rootFinancialStatement == null) { rootFinancialStatement = financialStatement; - rootFinancialStatement = financialStatementService.createFinancialStatement(null, rootFinancialStatement); + rootFinancialStatement = financialStatementService.createMasterFinacialStatements(rootFinancialStatement); } else { // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted // the sub financial statements @@ -527,15 +527,14 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ return alreadyCreated; } - protected FinancialStatement createRootFinancialStatement(Map<String, FinancialStatement> orderedFinancialStatements, String rootMasterName, final FinancialStatement rootFinancialStatement) throws AlreadyExistFinancialStatement, NotAllowedLabelException { - FinancialStatement _rootFinancialStatement = rootFinancialStatement; - if (_rootFinancialStatement == null) { - _rootFinancialStatement = financialStatementService.newFinancialStatement(); - _rootFinancialStatement.setLabel(rootMasterName); - _rootFinancialStatement = financialStatementService.createFinancialStatement(null, _rootFinancialStatement); - orderedFinancialStatements.put(rootMasterName, _rootFinancialStatement); + protected FinancialStatement createRootFinancialStatement(Map<String, FinancialStatement> orderedFinancialStatements, String rootMasterName, FinancialStatement rootFinancialStatement) throws AlreadyExistFinancialStatement, NotAllowedLabelException { + if (rootFinancialStatement == null) { + rootFinancialStatement = financialStatementService.newFinancialStatement(); + rootFinancialStatement.setLabel(rootMasterName); + rootFinancialStatement = financialStatementService.createMasterFinacialStatements(rootFinancialStatement); + orderedFinancialStatements.put(rootMasterName, rootFinancialStatement); } - return _rootFinancialStatement; + return rootFinancialStatement; } protected VatStatement returnVATStatement (final VatStatement rootVATStatement, String subVATStatementLabel) throws AlreadyExistVatStatementException, NotAllowedLabelException { diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartTreeTableModel.java b/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartTreeTableModel.java index b5f0cab..e2687e8 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartTreeTableModel.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartTreeTableModel.java @@ -26,14 +26,16 @@ import com.google.common.collect.Lists; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaSwingConfig; +import org.chorem.lima.business.LimaServiceFactory; import org.chorem.lima.business.api.FinancialStatementService; import org.chorem.lima.business.exceptions.AlreadyExistFinancialStatement; import org.chorem.lima.business.exceptions.NotAllowedLabelException; import org.chorem.lima.entity.FinancialStatement; import org.chorem.lima.entity.FinancialStatementImpl; -import org.chorem.lima.business.LimaServiceFactory; import org.chorem.lima.util.ErrorHelper; import org.jdesktop.swingx.treetable.AbstractTreeTableModel; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; import javax.swing.tree.TreePath; import java.util.List; @@ -58,16 +60,27 @@ public class FinancialStatementChartTreeTableModel extends AbstractTreeTableMode /** Services. */ protected final FinancialStatementService financialStatementService; + Binder<FinancialStatement, FinancialStatement> binderFinancialStatement; + protected ErrorHelper errorHelper; /** Model constructor. Init account service used here. */ public FinancialStatementChartTreeTableModel() { + //create root for the tree super(new FinancialStatementImpl()); - // Gets factory service + + // Gets factory service financialStatementService = LimaServiceFactory.getService(FinancialStatementService.class); + + FinancialStatement master = (FinancialStatement) root; + master.addAllSubFinancialStatements(financialStatementService.getRootFinancialStatements()); + errorHelper = new ErrorHelper(LimaSwingConfig.getInstance()); + + binderFinancialStatement = BinderFactory.newBinder(FinancialStatement.class); + } @@ -101,54 +114,33 @@ public class FinancialStatementChartTreeTableModel extends AbstractTreeTableMode @Override public int getChildCount(Object node) { - int result = 0; - if (node == getRoot()) { - result = financialStatementService. - getRootFinancialStatements().size(); - } else { - FinancialStatement parentFinancialStatementHeader = + FinancialStatement parentFinancialStatementHeader = (FinancialStatement) node; - result = parentFinancialStatementHeader.getSubFinancialStatements().size(); - } + int result = parentFinancialStatementHeader.sizeSubFinancialStatements(); return result; } @Override public Object getChild(Object parent, int index) { - Object result = null; - if (parent == getRoot()) { - List<FinancialStatement> financialStatements = - financialStatementService.getRootFinancialStatements(); - result = financialStatements.get(index); - } else { - FinancialStatement parentFinancialStatement = - (FinancialStatement) parent; + FinancialStatement parentFinancialStatement = + (FinancialStatement) parent; - List<FinancialStatement> financialStatements = - Lists.newArrayList(parentFinancialStatement.getSubFinancialStatements()); + List<FinancialStatement> financialStatements = + Lists.newArrayList(parentFinancialStatement.getSubFinancialStatements()); - result = financialStatements.get(index); - } + FinancialStatement result = financialStatements.get(index); return result; } @Override public int getIndexOfChild(Object parent, Object child) { - int result = 0; - - if (parent == getRoot()) { - List<FinancialStatement> financialStatements = - financialStatementService.getRootFinancialStatements(); - result = financialStatements.indexOf(child); - } else { - FinancialStatement parentFinancialStatement = - (FinancialStatement) parent; + FinancialStatement parentFinancialStatement = + (FinancialStatement) parent; - List<FinancialStatement> financialStatements = - Lists.newArrayList(parentFinancialStatement.getSubFinancialStatements()); + List<FinancialStatement> financialStatements = + Lists.newArrayList(parentFinancialStatement.getSubFinancialStatements()); - result = financialStatements.indexOf(child); - } + int result = financialStatements.indexOf(child); return result; } @@ -183,13 +175,17 @@ public class FinancialStatementChartTreeTableModel extends AbstractTreeTableMode @Override public boolean isLeaf(Object node) { - return getChildCount(node) == 0; + FinancialStatement financialStatement = (FinancialStatement) node; + return financialStatement != getRoot() && !financialStatement.isHeader(); } /** Refresh FinancialStatementChart. */ public void refreshTree() { + FinancialStatement master = (FinancialStatement) root; + master.setSubFinancialStatements(financialStatementService.getRootFinancialStatements()); + modelSupport.fireNewRoot(); } @@ -204,12 +200,22 @@ public class FinancialStatementChartTreeTableModel extends AbstractTreeTableMode // Calling account service FinancialStatement parentFinancialStatementHeader = (FinancialStatement) path.getLastPathComponent(); - if (parentFinancialStatementHeader == getRoot()) { - parentFinancialStatementHeader = null; - } + try { - financialStatementService.createFinancialStatement( - parentFinancialStatementHeader, financialStatement); + + if (parentFinancialStatementHeader == getRoot()) { + financialStatement = financialStatementService.createMasterFinacialStatements( + financialStatement); + parentFinancialStatementHeader.addSubFinancialStatements(financialStatement); + } else { + financialStatement = financialStatementService.createFinancialStatement( + parentFinancialStatementHeader, financialStatement); + binderFinancialStatement.copy(financialStatement.getMasterFinancialStatement(), parentFinancialStatementHeader); + } + + modelSupport.fireTreeStructureChanged(path); + + } catch (AlreadyExistFinancialStatement alreadyExistFinancialStatement) { errorHelper.showErrorMessage(t("lima.financialStatement.error.alreadyExistFinancialStatement", alreadyExistFinancialStatement.getFinancialStatementLabel(), alreadyExistFinancialStatement.getMasterLabel())); @@ -217,7 +223,6 @@ public class FinancialStatementChartTreeTableModel extends AbstractTreeTableMode errorHelper.showErrorMessage(t("lima.error.notAllowedLabel", notAllowedLabel.getLabel())); } - modelSupport.fireTreeStructureChanged(path); } @@ -229,8 +234,9 @@ public class FinancialStatementChartTreeTableModel extends AbstractTreeTableMode */ public void updateFinancialStatement(TreePath path, FinancialStatement financialStatement) { - financialStatementService.updateFinancialStatement(financialStatement); - modelSupport.fireTreeStructureChanged(path); + FinancialStatement updateFinancialStatement = financialStatementService.updateFinancialStatement(financialStatement); + binderFinancialStatement.copy(updateFinancialStatement, financialStatement); + modelSupport.firePathChanged(path); } diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java b/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java index e0f3e35..3fb4314 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java @@ -24,6 +24,7 @@ package org.chorem.lima.ui.financialstatementchart; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.LimaServiceFactory; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.FinancialStatementService; import org.chorem.lima.business.api.ImportService; @@ -32,15 +33,20 @@ import org.chorem.lima.entity.FinancialStatement; import org.chorem.lima.entity.FinancialStatementImpl; import org.chorem.lima.enums.FinancialStatementsChartEnum; import org.chorem.lima.enums.ImportExportEnum; -import org.chorem.lima.business.LimaServiceFactory; import org.chorem.lima.ui.importexport.ImportExport; import org.chorem.lima.util.ReportDialogView; import org.jdesktop.swingx.JXTreeTable; import org.nuiton.util.Resource; -import javax.swing.*; +import javax.swing.AbstractAction; +import javax.swing.ActionMap; +import javax.swing.InputMap; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.JTextArea; +import javax.swing.KeyStroke; import javax.swing.tree.TreePath; -import java.awt.*; +import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; @@ -255,18 +261,13 @@ public class FinancialStatementChartViewHandler implements ServiceListener { (FinancialStatementChartTreeTableModel) treeTable.getTreeTableModel(); // get selected account - int selectedRow = view.treeTable.getSelectedRow(); - TreePath treePath = view.treeTable.getPathForRow(selectedRow); // not null + int selectedRow = treeTable.getSelectedRow(); + TreePath treePath = treeTable.getPathForRow(selectedRow); // not null FinancialStatement financialStatement = (FinancialStatement) treePath.getLastPathComponent(); //update Account or update SubLedger if (financialStatement != null) { - // get current selection path - if (selectedRow != -1) { - treePath = view.treeTable.getPathForRow(selectedRow); - } else { - treePath = new TreePath(treeTableModel.getRoot()); - } + //test if selectedrow is account or ledger log.debug(financialStatement.isHeader()); if (financialStatement.isHeader()) { @@ -390,7 +391,11 @@ public class FinancialStatementChartViewHandler implements ServiceListener { (FinancialStatementsChartEnum) value; ImportExport importExport = new ImportExport(view); importExport.importExport(ImportExportEnum.CSV_FINANCIALSTATEMENTS_IMPORT, - null, financialStatementsEnum.getDefaultFileUrl(), true); + null, null, true); + + FinancialStatementChartTreeTableModel treeTableModel = (FinancialStatementChartTreeTableModel) view.getTreeTable().getTreeTableModel(); + + treeTableModel.refreshTree(); } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.