add validation for client notes.

This commit is contained in:
Keith Woodlock
2012-12-18 20:52:29 +00:00
parent 013276d9e4
commit 1fb04811d5
2 changed files with 19 additions and 5 deletions
@@ -1,5 +1,12 @@
package org.mifosplatform.portfolio.client.command; 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. * Immutable command used for create or update of notes.
*/ */
@@ -11,7 +18,14 @@ public class ClientNoteCommand {
this.note = note; this.note = note;
} }
public String getNote() { public void validate() {
return note; List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
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); }
} }
} }
@@ -174,7 +174,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
context.authenticatedUser(); context.authenticatedUser();
final ClientNoteCommand clientNoteCommand = this.clientNoteFromApiJsonDeserializer.commandFromApiJson(command.json()); final ClientNoteCommand clientNoteCommand = this.clientNoteFromApiJsonDeserializer.commandFromApiJson(command.json());
// FIXME - KW - no validation of note clientNoteCommand.validate();
final Client clientForUpdate = this.clientRepository.findOne(clientId); final Client clientForUpdate = this.clientRepository.findOne(clientId);
if (clientForUpdate == null) { throw new ClientNotFoundException(clientId); } if (clientForUpdate == null) { throw new ClientNotFoundException(clientId); }
@@ -193,7 +193,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
context.authenticatedUser(); context.authenticatedUser();
final ClientNoteCommand clientNoteCommand = this.clientNoteFromApiJsonDeserializer.commandFromApiJson(command.json()); final ClientNoteCommand clientNoteCommand = this.clientNoteFromApiJsonDeserializer.commandFromApiJson(command.json());
// FIXME - KW - no validation of note clientNoteCommand.validate();
final Note noteForUpdate = this.noteRepository.findOne(noteId); final Note noteForUpdate = this.noteRepository.findOne(noteId);
if (noteForUpdate == null || noteForUpdate.isNotAgainstClientWithIdOf(clientId)) { throw new NoteNotFoundException(noteId, if (noteForUpdate == null || noteForUpdate.isNotAgainstClientWithIdOf(clientId)) { throw new NoteNotFoundException(noteId,