This is an automated email from the ASF dual-hosted git repository. myrle pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/fineract-cn-customer.git
commit 48bfd66f9f7851aad38ac0a04bd4a73c35f6a8da Author: mgeiss <[email protected]> AuthorDate: Thu Sep 21 13:11:44 2017 +0200 fixed NPE when checking four eye task --- .../java/io/mifos/customer/TestTaskInstance.java | 33 +++++++++++++++++++++- .../rest/controller/CustomerRestController.java | 13 +++++---- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/component-test/src/main/java/io/mifos/customer/TestTaskInstance.java b/component-test/src/main/java/io/mifos/customer/TestTaskInstance.java index edce92c..53a6ba6 100644 --- a/component-test/src/main/java/io/mifos/customer/TestTaskInstance.java +++ b/component-test/src/main/java/io/mifos/customer/TestTaskInstance.java @@ -120,6 +120,10 @@ public class TestTaskInstance extends AbstractCustomerTest { final List<TaskDefinition> tasksForCustomer = this.customerManager.findTasksForCustomer(randomCustomer.getIdentifier(), false); Assert.assertEquals(1, tasksForCustomer.size()); + + taskDefinition.setPredefined(false); + this.customerManager.updateTask(taskDefinition.getIdentifier(), taskDefinition); + this.eventRecorder.wait(CustomerEventConstants.PUT_TASK, taskDefinition.getIdentifier()); } @Test @@ -197,7 +201,34 @@ public class TestTaskInstance extends AbstractCustomerTest { this.eventRecorder.wait(CustomerEventConstants.PUT_TASK, customTask1.getIdentifier()); customTask2.setPredefined(false); - this.customerManager.updateTask(customTask2.getIdentifier(), customTask1); + this.customerManager.updateTask(customTask2.getIdentifier(), customTask2); this.eventRecorder.wait(CustomerEventConstants.PUT_TASK, customTask2.getIdentifier()); } + + @Test(expected = TaskExecutionException.class) + public void shouldNotProceedFourEyesWrongSigner() throws Exception { + final TaskDefinition fourEyesTask = new TaskDefinition(); + fourEyesTask.setIdentifier("4-eyes-task-1"); + fourEyesTask.setType(TaskDefinition.Type.FOUR_EYES.name()); + fourEyesTask.setName("Do the barrel roll"); + fourEyesTask.setCommands( + TaskDefinition.Command.ACTIVATE.name() + ); + fourEyesTask.setPredefined(Boolean.TRUE); + fourEyesTask.setMandatory(Boolean.TRUE); + + this.customerManager.createTask(fourEyesTask); + this.eventRecorder.wait(CustomerEventConstants.POST_TASK, fourEyesTask.getIdentifier()); + + final Customer randomCustomer = CustomerGenerator.createRandomCustomer(); + this.customerManager.createCustomer(randomCustomer); + this.eventRecorder.wait(CustomerEventConstants.POST_CUSTOMER, randomCustomer.getIdentifier()); + + this.customerManager.taskForCustomerExecuted(randomCustomer.getIdentifier(), fourEyesTask.getIdentifier()); + this.eventRecorder.wait(CustomerEventConstants.PUT_CUSTOMER, randomCustomer.getIdentifier()); + + fourEyesTask.setPredefined(false); + this.customerManager.updateTask(fourEyesTask.getIdentifier(), fourEyesTask); + this.eventRecorder.wait(CustomerEventConstants.PUT_TASK, fourEyesTask.getIdentifier()); + } } diff --git a/service/src/main/java/io/mifos/customer/service/rest/controller/CustomerRestController.java b/service/src/main/java/io/mifos/customer/service/rest/controller/CustomerRestController.java index c3c6e94..d07124e 100644 --- a/service/src/main/java/io/mifos/customer/service/rest/controller/CustomerRestController.java +++ b/service/src/main/java/io/mifos/customer/service/rest/controller/CustomerRestController.java @@ -307,10 +307,12 @@ public class CustomerRestController { @ResponseBody ResponseEntity<Void> taskForCustomerExecuted(@PathVariable("identifier") final String identifier, @PathVariable("taskIdentifier") final String taskIdentifier) { - if (this.customerService.customerExists(identifier)) { - if (this.taskService.taskDefinitionExists(taskIdentifier)) { - final TaskDefinition taskDefinition = this.taskService.findByIdentifier(taskIdentifier).get(); - final Customer customer; + final Optional<Customer> optionalCustomer = this.customerService.findCustomer(identifier); + if (optionalCustomer.isPresent()) { + final Customer customer = optionalCustomer.get(); + final Optional<TaskDefinition> optionalTaskDefinition = this.taskService.findByIdentifier(taskIdentifier); + if (optionalTaskDefinition.isPresent()) { + final TaskDefinition taskDefinition = optionalTaskDefinition.get(); switch (TaskDefinition.Type.valueOf(taskDefinition.getType())) { case ID_CARD: final List<IdentificationCard> identificationCards = this.customerService.fetchIdentificationCardsByCustomer(identifier); @@ -319,8 +321,7 @@ public class CustomerRestController { } break; case FOUR_EYES: - customer = this.customerService.findCustomer(identifier).get(); - if (customer.getAssignedEmployee().equals(UserContextHolder.checkedGetUser())) { + if (customer.getCreatedBy().equals(UserContextHolder.checkedGetUser())) { throw ServiceException.conflict("Signing user must be different than creator."); } break; -- To stop receiving notification emails like this one, please contact [email protected].
