r3945 - in trunk: pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1 pollen-services/src/main/java/org/chorem/pollen/services/service
Author: tchemit Date: 2014-05-15 12:35:46 +0200 (Thu, 15 May 2014) New Revision: 3945 Url: http://forge.chorem.org/projects/pollen/repository/revisions/3945 Log: can not delete last choice of a poll Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java 2014-05-15 10:32:05 UTC (rev 3944) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java 2014-05-15 10:35:46 UTC (rev 3945) @@ -69,7 +69,7 @@ } - public void deleteChoice(ChoiceService choiceService, String pollId, String choiceId) { + public void deleteChoice(ChoiceService choiceService, String pollId, String choiceId) throws InvalidFormException { choiceService.deleteChoice(pollId, choiceId); Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java 2014-05-15 10:32:05 UTC (rev 3944) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java 2014-05-15 10:35:46 UTC (rev 3945) @@ -138,7 +138,7 @@ } - public void deleteChoice(String pollId, String choiceId) { + public void deleteChoice(String pollId, String choiceId) throws InvalidFormException { checkNotNull(pollId); checkNotNull(choiceId); @@ -147,6 +147,16 @@ Poll poll = getPollService().getPoll0(pollId); Choice choice = getChoice(poll, choiceId); + List<Choice> existingChoices = getChoiceDao().findAll(poll); + if (existingChoices.size() == 1) { + + // can't delete this choice + // will be the last one + ErrorMap errors = new ErrorMap(); + errors.addError("choice", "need at least one choice"); + errors.failIfNotEmpty(); + } + //TODO Check if this is not the last choice, if so can not delete getChoiceDao().delete(choice); commit();
participants (1)
-
tchemit@users.chorem.org