MIFOSX-1954 End date is validated if it is before startDate.Validation function merged for Create/Update teller.
This commit is contained in:
+3
-29
@@ -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<Map<String, Object>>() {}.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<Map<String, Object>>() {}.getType();
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters);
|
||||
|
||||
final List<ApiParameterError> 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(); }
|
||||
|
||||
|
||||
+2
-2
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user