add validation for client notes.
This commit is contained in:
+16
-2
@@ -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<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); }
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user