wip:fixing collection sheet bugs
This commit is contained in:
+2
-2
@@ -156,13 +156,13 @@ public class CalendarCommandFromApiJsonDeserializer extends AbstractFromApiJsonD
|
|||||||
if (this.fromApiJsonHelper.parameterExists(CALENDAR_SUPPORTED_PARAMETERS.FIRST_REMINDER.getValue(), element)) {
|
if (this.fromApiJsonHelper.parameterExists(CALENDAR_SUPPORTED_PARAMETERS.FIRST_REMINDER.getValue(), element)) {
|
||||||
final Integer firstReminder = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(
|
final Integer firstReminder = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(
|
||||||
CALENDAR_SUPPORTED_PARAMETERS.FIRST_REMINDER.getValue(), element);
|
CALENDAR_SUPPORTED_PARAMETERS.FIRST_REMINDER.getValue(), element);
|
||||||
baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.FIRST_REMINDER.getValue()).value(firstReminder).notNull();
|
baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.FIRST_REMINDER.getValue()).value(firstReminder).ignoreIfNull().integerGreaterThanZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.fromApiJsonHelper.parameterExists(CALENDAR_SUPPORTED_PARAMETERS.SECOND_REMINDER.getValue(), element)) {
|
if (this.fromApiJsonHelper.parameterExists(CALENDAR_SUPPORTED_PARAMETERS.SECOND_REMINDER.getValue(), element)) {
|
||||||
final Integer secondReminder = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(
|
final Integer secondReminder = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(
|
||||||
CALENDAR_SUPPORTED_PARAMETERS.SECOND_REMINDER.getValue(), element);
|
CALENDAR_SUPPORTED_PARAMETERS.SECOND_REMINDER.getValue(), element);
|
||||||
baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.SECOND_REMINDER.getValue()).value(secondReminder).notNull();
|
baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.SECOND_REMINDER.getValue()).value(secondReminder).ignoreIfNull().integerGreaterThanZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||||
|
|||||||
+32
-2
@@ -1,7 +1,9 @@
|
|||||||
package org.mifosplatform.portfolio.collectionsheet.api;
|
package org.mifosplatform.portfolio.collectionsheet.api;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
@@ -15,12 +17,16 @@ import javax.ws.rs.core.Context;
|
|||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.UriInfo;
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.mifosplatform.commands.domain.CommandWrapper;
|
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||||
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
||||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||||
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||||
|
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||||
import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
|
import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
|
||||||
import org.mifosplatform.infrastructure.core.service.DateUtils;
|
import org.mifosplatform.infrastructure.core.service.DateUtils;
|
||||||
@@ -46,7 +52,7 @@ public class CollectionSheetApiResource {
|
|||||||
/*
|
/*
|
||||||
* dueDate format is ISO 8601 Calendar Date (YYYYMMDD)
|
* dueDate format is ISO 8601 Calendar Date (YYYYMMDD)
|
||||||
*/
|
*/
|
||||||
private final String datePattern = "YYYYMMDD";
|
private final String datePattern = "yyyyMMdd";
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final CollectionSheetReadPlatformService collectionSheetReadPlatformService;
|
private final CollectionSheetReadPlatformService collectionSheetReadPlatformService;
|
||||||
private final ToApiJsonSerializer<JLGCollectionSheetData> toApiJsonSerializer;
|
private final ToApiJsonSerializer<JLGCollectionSheetData> toApiJsonSerializer;
|
||||||
@@ -72,13 +78,37 @@ public class CollectionSheetApiResource {
|
|||||||
@QueryParam("dueDate") final String dueDate) {
|
@QueryParam("dueDate") final String dueDate) {
|
||||||
|
|
||||||
this.context.authenticatedUser().validateHasReadPermission("COLLECTIONSHEET");
|
this.context.authenticatedUser().validateHasReadPermission("COLLECTIONSHEET");
|
||||||
final LocalDate localDate = DateUtils.parseLocalDate(dueDate, this.datePattern);
|
|
||||||
|
validateRequest(groupId, dueDate);
|
||||||
|
|
||||||
|
LocalDate localDate = null;
|
||||||
|
if(StringUtils.isBlank(dueDate)){
|
||||||
|
localDate = DateUtils.getLocalDateOfTenant();
|
||||||
|
}else{
|
||||||
|
localDate = DateUtils.parseLocalDate(dueDate, datePattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
final JLGCollectionSheetData collectionSheet = this.collectionSheetReadPlatformService.retriveCollectionSheet(localDate, groupId);
|
final JLGCollectionSheetData collectionSheet = this.collectionSheetReadPlatformService.retriveCollectionSheet(localDate, groupId);
|
||||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||||
return this.toApiJsonSerializer.serialize(settings, collectionSheet, this.COLLECTIONSHEET_DATA_PARAMETERS);
|
return this.toApiJsonSerializer.serialize(settings, collectionSheet, this.COLLECTIONSHEET_DATA_PARAMETERS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateRequest(Long groupId, String dueDate) {
|
||||||
|
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
|
||||||
|
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("collectionsheet");
|
||||||
|
|
||||||
|
baseDataValidator.reset().parameter("groupId").value(groupId).notBlank().longGreaterThanZero();
|
||||||
|
|
||||||
|
baseDataValidator.reset().parameter("dueDate").value(dueDate).notBlank();
|
||||||
|
|
||||||
|
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||||
|
"Validation errors exist.", dataValidationErrors); }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
|||||||
+14
-11
@@ -3,6 +3,8 @@ package org.mifosplatform.portfolio.collectionsheet.service;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -145,15 +147,15 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe
|
|||||||
// FIXME Need to check last loan is added under previous
|
// FIXME Need to check last loan is added under previous
|
||||||
// client/group or new client / previous group or new client / new
|
// client/group or new client / previous group or new client / new
|
||||||
// group
|
// group
|
||||||
|
if(corrCollectioSheetFlatData != null){
|
||||||
final ClientLoansData lastClientLoansData = corrCollectioSheetFlatData.getClientLoansData();
|
final ClientLoansData lastClientLoansData = corrCollectioSheetFlatData.getClientLoansData();
|
||||||
lastClientLoansData.setLoans(loanDueDatas);
|
lastClientLoansData.setLoans(loanDueDatas);
|
||||||
clientLoansDatas.add(lastClientLoansData);
|
clientLoansDatas.add(lastClientLoansData);
|
||||||
|
|
||||||
final JLGClientsData jlgClientsData = corrCollectioSheetFlatData.getJLGClientsData();
|
final JLGClientsData jlgClientsData = corrCollectioSheetFlatData.getJLGClientsData();
|
||||||
jlgClientsData.setClients(clientLoansDatas);
|
jlgClientsData.setClients(clientLoansDatas);
|
||||||
|
jlgClientsDatas.add(jlgClientsData);
|
||||||
jlgClientsDatas.add(jlgClientsData);
|
}
|
||||||
|
|
||||||
jlgCollectionSheetData = new JLGCollectionSheetData(dueDate, loanProducts, jlgClientsDatas);
|
jlgCollectionSheetData = new JLGCollectionSheetData(dueDate, loanProducts, jlgClientsDatas);
|
||||||
}
|
}
|
||||||
@@ -167,9 +169,10 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe
|
|||||||
|
|
||||||
final JLGCollectionSheetFaltDataMapper mapper = new JLGCollectionSheetFaltDataMapper();
|
final JLGCollectionSheetFaltDataMapper mapper = new JLGCollectionSheetFaltDataMapper();
|
||||||
final String sql = mapper.collectionSheetSchema();
|
final String sql = mapper.collectionSheetSchema();
|
||||||
|
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
final String dueDateStr = df.format(dueDate.toDate());
|
||||||
final SqlParameterSource namedParameters = new MapSqlParameterSource().addValue("hierarchy", groupHierarchy)
|
final SqlParameterSource namedParameters = new MapSqlParameterSource().addValue("hierarchy", groupHierarchy)
|
||||||
.addValue("dueDate", dueDate).addValue("officeHierarchy", officeHierarchy);
|
.addValue("dueDate", dueDateStr).addValue("officeHierarchy", officeHierarchy);
|
||||||
return this.namedParameterjdbcTemplate.query(sql, namedParameters, mapper);
|
return this.namedParameterjdbcTemplate.query(sql, namedParameters, mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user