From 1fb04811d5128841e1e73b666d9da032622fde31 Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Tue, 18 Dec 2012 20:52:29 +0000 Subject: [PATCH] add validation for client notes. --- .../client/command/ClientNoteCommand.java | 18 ++++++++++++++++-- ...tWritePlatformServiceJpaRepositoryImpl.java | 6 +++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/command/ClientNoteCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/command/ClientNoteCommand.java index 55c5863c1..4b9e4bf1f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/command/ClientNoteCommand.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/command/ClientNoteCommand.java @@ -1,5 +1,12 @@ package org.mifosplatform.portfolio.client.command; +import java.util.ArrayList; +import java.util.List; + +import org.mifosplatform.infrastructure.core.data.ApiParameterError; +import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; +import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; + /** * Immutable command used for create or update of notes. */ @@ -11,7 +18,14 @@ public class ClientNoteCommand { this.note = note; } - public String getNote() { - return note; + public void validate() { + List dataValidationErrors = new ArrayList(); + + DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("clientnote"); + + baseDataValidator.reset().parameter("note").value(this.note).notBlank().notExceedingLengthOf(1000); + + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", + "Validation errors exist.", dataValidationErrors); } } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java index 52c81be26..8ce3f8f87 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java @@ -174,8 +174,8 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP context.authenticatedUser(); final ClientNoteCommand clientNoteCommand = this.clientNoteFromApiJsonDeserializer.commandFromApiJson(command.json()); - // FIXME - KW - no validation of note - + clientNoteCommand.validate(); + final Client clientForUpdate = this.clientRepository.findOne(clientId); if (clientForUpdate == null) { throw new ClientNotFoundException(clientId); } @@ -193,7 +193,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP context.authenticatedUser(); final ClientNoteCommand clientNoteCommand = this.clientNoteFromApiJsonDeserializer.commandFromApiJson(command.json()); - // FIXME - KW - no validation of note + clientNoteCommand.validate(); final Note noteForUpdate = this.noteRepository.findOne(noteId); if (noteForUpdate == null || noteForUpdate.isNotAgainstClientWithIdOf(clientId)) { throw new NoteNotFoundException(noteId,