From 9080e7ecb403341a1c52c329d044a778cc254f0f Mon Sep 17 00:00:00 2001 From: Susana Montes Pedreira Date: Mon, 18 Jun 2012 09:00:06 +0100 Subject: [PATCH] implements an empty method called "beforeSaving" in the GenericRESTService and overrides it in the ExpenseSheetServiceRest in order to save the sum of expenses. FEA: ItEr76S22ExpenseTrackingSystem --- .../ws/common/impl/GenericRESTService.java | 8 +++ .../impl/ExpenseSheetServiceREST.java | 57 ++----------------- 2 files changed, 13 insertions(+), 52 deletions(-) diff --git a/libreplan-webapp/src/main/java/org/libreplan/ws/common/impl/GenericRESTService.java b/libreplan-webapp/src/main/java/org/libreplan/ws/common/impl/GenericRESTService.java index 3ca7948b1..278bad001 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/ws/common/impl/GenericRESTService.java +++ b/libreplan-webapp/src/main/java/org/libreplan/ws/common/impl/GenericRESTService.java @@ -141,6 +141,7 @@ public abstract class GenericRESTService - * - */ - protected void insertOrUpdate(final ExpenseSheetDTO entityDTO) - throws ValidationException, RecoverableErrorException { - /* - * NOTE: ValidationException and RecoverableErrorException are runtime - * exceptions. In consequence, if any of them occurs, transaction is - * automatically rolled back. - */ - - IOnTransaction save = new IOnTransaction() { - - @Override - public Void execute() { - - ExpenseSheet entity = null; - IIntegrationEntityDAO entityDAO = getIntegrationEntityDAO(); - - /* Insert or update? */ - try { - entity = entityDAO.findByCode(entityDTO.code); - updateEntity(entity, entityDTO); - } catch (InstanceNotFoundException e) { - entity = toEntity(entityDTO); - } - - /* - * Validate and save (insert or update) the entity. - */ - entity.validate(); - sumExpensesDAO - .updateRelatedSumExpensesWithExpenseSheetLineSet(entity - .getExpenseSheetLines()); - entity.updateCalculatedProperties(); - - entityDAO.saveWithoutValidating(entity); - - return null; - - } - - }; - - transactionService.runOnAnotherTransaction(save); + @Override + protected void beforeSaving(ExpenseSheet entity) { + sumExpensesDAO.updateRelatedSumExpensesWithExpenseSheetLineSet(entity + .getExpenseSheetLines()); + entity.updateCalculatedProperties(); } @Override