changes the InstanceNotFoundException to ValidationException and if

the entity is not found the function returns a null.

FEA: ItEr76S22ExpenseTrackingSystem
This commit is contained in:
Susana Montes Pedreira 2012-06-17 13:21:34 +01:00
parent 5386c1eec5
commit 57f23e37fe
2 changed files with 10 additions and 11 deletions

View file

@ -35,7 +35,7 @@ import org.libreplan.business.common.IHumanIdentifiable;
import org.libreplan.business.common.IntegrationEntity;
import org.libreplan.business.common.Registry;
import org.libreplan.business.common.entities.EntitySequence;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.common.exceptions.ValidationException;
import org.libreplan.business.expensesheet.daos.IExpenseSheetDAO;
import org.libreplan.business.resources.entities.Resource;
@ -211,11 +211,11 @@ public class ExpenseSheet extends IntegrationEntity implements IHumanIdentifiabl
}
public ExpenseSheetLine getExpenseSheetLineByCode(String code)
throws InstanceNotFoundException {
throws ValidationException {
if (StringUtils.isBlank(code)) {
throw new InstanceNotFoundException(code,
ExpenseSheetLine.class.getName());
throw new ValidationException(
"missing the code with which find the expense sheet line");
}
for (ExpenseSheetLine l : this.expenseSheetLines) {
@ -223,9 +223,7 @@ public class ExpenseSheet extends IntegrationEntity implements IHumanIdentifiabl
return l;
}
}
throw new InstanceNotFoundException(code,
ExpenseSheetLine.class.getName());
return null;
}
public boolean isPersonal() {

View file

@ -201,13 +201,14 @@ public final class ExpenseSheetConverter {
"missing code in a expense sheet line");
}
try {
ExpenseSheetLine line = expenseSheet
.getExpenseSheetLineByCode(lineDTO.code);
ExpenseSheetLine line = expenseSheet
.getExpenseSheetLineByCode(lineDTO.code);
if (line != null) {
updateExpenseSheetLine(line, lineDTO);
} catch (InstanceNotFoundException e) {
} else {
expenseSheet.add(toEntity(lineDTO, expenseSheet));
}
}
}