From b0173fa46a011af177ca0cc65b2ed05711a1d2bb Mon Sep 17 00:00:00 2001 From: Chandrika Date: Thu, 9 Apr 2015 11:30:59 -0400 Subject: [PATCH] MIFOSX-1954 End date is validated if it is before startDate.Validation function merged for Create/Update teller. --- .../TellerCommandFromApiJsonDeserializer.java | 32 ++----------------- .../TellerWritePlatformServiceJpaImpl.java | 4 +-- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/teller/serialization/TellerCommandFromApiJsonDeserializer.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/teller/serialization/TellerCommandFromApiJsonDeserializer.java index da355a6a0..4e854f307 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/teller/serialization/TellerCommandFromApiJsonDeserializer.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/teller/serialization/TellerCommandFromApiJsonDeserializer.java @@ -50,7 +50,7 @@ public final class TellerCommandFromApiJsonDeserializer { this.fromApiJsonHelper = fromApiJsonHelper; } - public void validateForCreate(final String json) { + public void validateForCreateAndUpdateTeller(final String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); @@ -74,13 +74,13 @@ public final class TellerCommandFromApiJsonDeserializer { baseDataValidator.reset().parameter("startDate").value(startDate).notNull(); final LocalDate endDate = this.fromApiJsonHelper.extractLocalDateNamed("endDate", element); - baseDataValidator.reset().parameter("startDate").value(endDate).ignoreIfNull(); + baseDataValidator.reset().parameter("endDate").value(endDate).ignoreIfNull(); final String status = this.fromApiJsonHelper.extractStringNamed("status", element); baseDataValidator.reset().parameter("status").value(status).notBlank().notExceedingLengthOf(50); if (endDate != null) { - if (endDate.isAfter(startDate)) { throw new InvalidDateInputException(startDate.toString(), endDate.toString()); } + if (endDate.isBefore(startDate)) { throw new InvalidDateInputException(startDate.toString(), endDate.toString()); } } throwExceptionIfValidationWarningsExist(dataValidationErrors); } @@ -90,32 +90,6 @@ public final class TellerCommandFromApiJsonDeserializer { "Validation errors exist.", dataValidationErrors); } } - public void validateForUpdate(final String json) { - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - final Type typeOfMap = new TypeToken>() {}.getType(); - this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters); - - final List dataValidationErrors = new ArrayList<>(); - final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("teller"); - - final JsonElement element = this.fromApiJsonHelper.parse(json); - - final String name = this.fromApiJsonHelper.extractStringNamed("name", element); - baseDataValidator.reset().parameter("name").value(name).notBlank().notExceedingLengthOf(50); - - final String description = this.fromApiJsonHelper.extractStringNamed("description", element); - baseDataValidator.reset().parameter("description").value(description).notBlank().notExceedingLengthOf(100); - - final LocalDate startDate = this.fromApiJsonHelper.extractLocalDateNamed("startDate", element); - baseDataValidator.reset().parameter("startDate").value(startDate).notNull(); - - final String status = this.fromApiJsonHelper.extractStringNamed("status", element); - baseDataValidator.reset().parameter("status").value(status).notBlank().notExceedingLengthOf(50); - - throwExceptionIfValidationWarningsExist(dataValidationErrors); - } - public void validateForAllocateCashier(final String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/teller/service/TellerWritePlatformServiceJpaImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/teller/service/TellerWritePlatformServiceJpaImpl.java index 08343f6c3..6eb9a4c5d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/teller/service/TellerWritePlatformServiceJpaImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/teller/service/TellerWritePlatformServiceJpaImpl.java @@ -90,7 +90,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer final Long officeId = command.longValueOfParameterNamed("officeId"); - this.fromApiJsonDeserializer.validateForCreate(command.json()); + this.fromApiJsonDeserializer.validateForCreateAndUpdateTeller(command.json()); // final Office parent = // validateUserPriviledgeOnOfficeAndRetrieve(currentUser, officeId); @@ -124,7 +124,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer final AppUser currentUser = this.context.authenticatedUser(); - this.fromApiJsonDeserializer.validateForUpdate(command.json()); + this.fromApiJsonDeserializer.validateForCreateAndUpdateTeller(command.json()); final Teller teller = validateUserPriviledgeOnTellerAndRetrieve(currentUser, tellerId);