data validation error holiday name appearing twice(fixed)
This commit is contained in:
+22
-23
@@ -1,4 +1,4 @@
|
|||||||
package org.mifosplatform.organisation.holiday.data;
|
package org.mifosplatform.organisation.holiday.data;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -26,18 +26,18 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
@Component
|
@Component
|
||||||
public class HolidayDataValidator {
|
public class HolidayDataValidator {
|
||||||
|
|
||||||
private final FromJsonHelper fromApiJsonHelper;
|
private final FromJsonHelper fromApiJsonHelper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public HolidayDataValidator(final FromJsonHelper fromApiJsonHelper) {
|
public HolidayDataValidator(final FromJsonHelper fromApiJsonHelper) {
|
||||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void validateForCreate(final String json) {
|
public void validateForCreate(final String json) {
|
||||||
|
|
||||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||||
|
|
||||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, HolidayApiConstants.HOLIDAY_CREATE_REQUEST_DATA_PARAMETERS);
|
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, HolidayApiConstants.HOLIDAY_CREATE_REQUEST_DATA_PARAMETERS);
|
||||||
final JsonElement element = fromApiJsonHelper.parse(json);
|
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||||
|
|
||||||
@@ -47,36 +47,35 @@ public class HolidayDataValidator {
|
|||||||
.resource(HolidayApiConstants.HOLIDAY_RESOURCE_NAME);
|
.resource(HolidayApiConstants.HOLIDAY_RESOURCE_NAME);
|
||||||
|
|
||||||
final String name = this.fromApiJsonHelper.extractStringNamed(HolidayApiConstants.name, element);
|
final String name = this.fromApiJsonHelper.extractStringNamed(HolidayApiConstants.name, element);
|
||||||
baseDataValidator.reset().parameter(HolidayApiConstants.name).value(name).notBlank().notNull().notExceedingLengthOf(100);
|
baseDataValidator.reset().parameter(HolidayApiConstants.name).value(name).notNull().notExceedingLengthOf(100);
|
||||||
|
|
||||||
final LocalDate fromDate = this.fromApiJsonHelper.extractLocalDateNamed(HolidayApiConstants.fromDate, element);
|
final LocalDate fromDate = this.fromApiJsonHelper.extractLocalDateNamed(HolidayApiConstants.fromDate, element);
|
||||||
baseDataValidator.reset().parameter(HolidayApiConstants.fromDate).value(fromDate).notNull();
|
baseDataValidator.reset().parameter(HolidayApiConstants.fromDate).value(fromDate).notNull();
|
||||||
|
|
||||||
final LocalDate toDate = this.fromApiJsonHelper.extractLocalDateNamed(HolidayApiConstants.toDate, element);
|
final LocalDate toDate = this.fromApiJsonHelper.extractLocalDateNamed(HolidayApiConstants.toDate, element);
|
||||||
baseDataValidator.reset().parameter(HolidayApiConstants.toDate).value(toDate).notNull();
|
baseDataValidator.reset().parameter(HolidayApiConstants.toDate).value(toDate).notNull();
|
||||||
|
|
||||||
|
|
||||||
Set<Long> offices = null;
|
Set<Long> offices = null;
|
||||||
final JsonObject topLevelJsonElement = element.getAsJsonObject();
|
final JsonObject topLevelJsonElement = element.getAsJsonObject();
|
||||||
|
|
||||||
if (topLevelJsonElement.has(HolidayApiConstants.offices)&&topLevelJsonElement.get(HolidayApiConstants.offices).isJsonArray()) {
|
if (topLevelJsonElement.has(HolidayApiConstants.offices) && topLevelJsonElement.get(HolidayApiConstants.offices).isJsonArray()) {
|
||||||
|
|
||||||
final JsonArray array = topLevelJsonElement.get(HolidayApiConstants.offices).getAsJsonArray();
|
final JsonArray array = topLevelJsonElement.get(HolidayApiConstants.offices).getAsJsonArray();
|
||||||
if(array.size()>0) {
|
if (array.size() > 0) {
|
||||||
offices = new HashSet<Long>(array.size());
|
offices = new HashSet<Long>(array.size());
|
||||||
for (int i = 0; i < array.size(); i++) {
|
for (int i = 0; i < array.size(); i++) {
|
||||||
final JsonObject officeElement = array.get(i).getAsJsonObject();
|
final JsonObject officeElement = array.get(i).getAsJsonObject();
|
||||||
final Long officeId = this.fromApiJsonHelper.extractLongNamed("officeId", officeElement);
|
final Long officeId = this.fromApiJsonHelper.extractLongNamed("officeId", officeElement);
|
||||||
baseDataValidator.reset().parameter(HolidayApiConstants.offices).value(officeId).notNull();
|
baseDataValidator.reset().parameter(HolidayApiConstants.offices).value(officeId).notNull();
|
||||||
offices.add(officeId);
|
offices.add(officeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
baseDataValidator.reset().parameter(HolidayApiConstants.offices).value(offices).notNull();
|
baseDataValidator.reset().parameter(HolidayApiConstants.offices).value(offices).notNull();
|
||||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
|
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
|
||||||
if (!dataValidationErrors.isEmpty()) {
|
if (!dataValidationErrors.isEmpty()) {
|
||||||
//
|
//
|
||||||
throw new PlatformApiDataValidationException(dataValidationErrors);
|
throw new PlatformApiDataValidationException(dataValidationErrors);
|
||||||
|
|||||||
Reference in New Issue
Block a user