Skip to content

Commit

Permalink
Merge pull request #210 from fiterlatam/feature/FBR-313
Browse files Browse the repository at this point in the history
Feature/fbr314
  • Loading branch information
BrianMuhimbura authored Oct 5, 2023
2 parents aa8de3b + f10a24a commit 5b43952
Show file tree
Hide file tree
Showing 17 changed files with 363 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3926,4 +3926,20 @@ public CommandWrapperBuilder sendGroupForAnalysis(Long prequalificationId) {
this.href = "/prequalification/checklist/" + prequalificationId;
return this;
}

public CommandWrapperBuilder updatePrequalificationMemberDetails(Long memberId) {
this.actionName = "UPDATE";
this.entityName = "PREQUALIFICATIONMEMBER";
this.entityId = memberId;
this.href = "/prequalification/" + memberId;
return this;
}

public CommandWrapperBuilder processAnalysisRequest(Long prequalificationId) {
this.actionName = "PROCESSANALYSIS";
this.entityName = "PREQUALIFICATIONS";
this.entityId = prequalificationId;
this.href = "/prequalification/checklist/" + prequalificationId;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,27 @@ public String updatePrequalification(@Parameter(hidden = true) final String apiR
}
}

@PUT
@Path("/{groupId}/{memberId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String updatePrequalificationMember(@Parameter(hidden = true) final String apiRequestBodyAsJson,
@PathParam("groupId") @Parameter(description = "groupId") final Long groupId,
@PathParam("memberId") @Parameter(description = "memberId") final Long memberId) {

try {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updatePrequalificationMemberDetails(memberId)
.withJson(apiRequestBodyAsJson).build();

final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);

return this.toApiJsonSerializer.serialize(result);
} catch (final Exception e) {
e.printStackTrace();
throw e;
}
}

@POST
@Path("/{groupId}/comment")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,23 @@ public String validateHardPolicyChecklist(@PathParam("prequalificationId") final
} else if (is(commandParam, "sendToAnalysis")) {
final CommandWrapper validateCommandRequest = builder.sendGroupForAnalysis(prequalificationId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(validateCommandRequest);
} else if (is(commandParam, "sendtoexception")) {
final CommandWrapper validateCommandRequest = builder.processAnalysisRequest(prequalificationId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(validateCommandRequest);
} else if (is(commandParam, "sendtoagency")) {
final CommandWrapper validateCommandRequest = builder.processAnalysisRequest(prequalificationId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(validateCommandRequest);
} else if (is(commandParam, "rejectanalysis")) {
final CommandWrapper validateCommandRequest = builder.processAnalysisRequest(prequalificationId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(validateCommandRequest);
} else if (is(commandParam, "approveanalysis")) {
final CommandWrapper validateCommandRequest = builder.processAnalysisRequest(prequalificationId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(validateCommandRequest);
} else {
final CommandWrapper commandRequest = builder.validatePrequalificationHardPolicies(prequalificationId).build();
final CommandWrapper commandRequest = builder.processAnalysisRequest(prequalificationId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
}

return this.toApiJsonSerializer.serialize(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ public class PrequalificationCollectionConstants extends PrequalificatoinApiCons
membersParamName, dateFormatParamName, localeParamName, agencyIdParamName, facilitatorParamName, "individual",
prequalificationNumberParamName, prequalilficationTimespanParamName, previousPrequalificationParamName));

protected static final Set<String> EDIT_MEMBER_PREQUALIFICATION_REQUEST_DATA_PARAMETERS = new HashSet<>(
Arrays.asList(memberIdParamName, memberNameParamName, memberDpiParamName, memberDobParamName, memberRequestedAmountParamName,
memberWorkWithPuenteParamName, memberStatusParamName, approvedAmountParamName, localeParamName, dateFormatParamName));

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -122,4 +123,27 @@ private void throwExceptionIfValidationWarningsExist(final List<ApiParameterErro
}
}

public void validateUpdateMember(String json) {
if (StringUtils.isBlank(json)) {
throw new InvalidJsonException();
}
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();

final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json,
PrequalificationCollectionConstants.EDIT_MEMBER_PREQUALIFICATION_REQUEST_DATA_PARAMETERS);

final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
.resource(PrequalificatoinApiConstants.PREQUALIFICATION_RESOURCE_NAME);

final JsonElement element = this.fromApiJsonHelper.parse(json);

if (this.fromApiJsonHelper.parameterExists(PrequalificatoinApiConstants.approvedAmountParamName, element)) {
final BigDecimal approvedAmount = this.fromApiJsonHelper
.extractBigDecimalWithLocaleNamed(PrequalificatoinApiConstants.approvedAmountParamName, element);
baseDataValidator.reset().parameter(PrequalificatoinApiConstants.approvedAmountParamName).value(approvedAmount).notNull()
.longGreaterThanZero();
}
throwExceptionIfValidationWarningsExist(dataValidationErrors);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public class PrequalificatoinApiConstants {
public static final String previousPrequalificationParamName = "previousPrequalification";

// Members
public static final String memberIdParamName = "id";
public static final String memberNameParamName = "name";
public static final String memberDpiParamName = "dpi";
public static final String memberDobParamName = "dob";
public static final String memberRequestedAmountParamName = "requestedAmount";
public static final String memberWorkWithPuenteParamName = "workWithPuente";
public static final String memberStatusParamName = "status";
public static final String memberClientIdParamName = "clientId";
public static String approvedAmountParamName = "approvedAmount";
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.fineract.organisation.prequalification.data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -72,6 +73,8 @@ public class GroupPrequalificationData {
private Long prequalilficationTimespan;
private Collection<MemberPrequalificationData> groupMembers;
private Collection<EnumOptionData> groupStatusOptions;
private BigDecimal totalRequestedAmount;
private BigDecimal totalApprovedAmount;

public GroupPrequalificationData(final Long id, final String productName, final String prequalificationNumber, final String agencyName,
final String portforlioName, final String centerName, final String groupName, final String addedBy, final LocalDate createdAt,
Expand Down Expand Up @@ -107,6 +110,8 @@ public GroupPrequalificationData(final Long id, final String productName, final
this.statusChangedOn = null;
this.processType = null;
this.processQuality = null;
this.totalRequestedAmount = null;
this.totalApprovedAmount = null;
}

public GroupPrequalificationData(final Long id, final String productName, final String prequalificationNumber, final String agencyName,
Expand All @@ -116,7 +121,8 @@ public GroupPrequalificationData(final Long id, final String productName, final
Collection<AppUserData> appUsers, final Long agencyId, final Long centerId, final Long productId, final Long facilitatorId,
final String facilitatorName, Long greenValidationCount, Long yellowValidationCount, Long orangeValidationCount,
Long redValidationCount, Long prequalilficationTimespan, EnumOptionData lastPrequalificationStatus, String statusChangedBy,
LocalDate statusChangedOn, String processType, String processQuality) {
LocalDate statusChangedOn, String processType, String processQuality, BigDecimal totalRequestedAmount,
BigDecimal totalApprovedAmount) {
this.id = id;
this.productName = productName;
this.prequalificationNumber = prequalificationNumber;
Expand Down Expand Up @@ -149,6 +155,8 @@ public GroupPrequalificationData(final Long id, final String productName, final
this.statusChangedOn = statusChangedOn;
this.processType = processType;
this.processQuality = processQuality;
this.totalRequestedAmount = totalRequestedAmount;
this.totalApprovedAmount = totalApprovedAmount;
}

public static GroupPrequalificationData template(final Collection<AgencyData> agencies, Collection<CenterData> centerData,
Expand All @@ -173,11 +181,13 @@ public static GroupPrequalificationData instance(Long id, String prequalificatio
String comments, Long groupId, final Long agencyId, final Long centerId, final Long productId, final Long facilitatorId,
final String facilitatorName, Long greenValidationCount, Long yellowValidationCount, Long orangeValidationCount,
Long redValidationCount, Long prequalilficationTimespan, EnumOptionData lastPrequalificationStatus, String statusChangedBy,
LocalDate statusChangedOn, String processType, String processQuality) {
LocalDate statusChangedOn, String processType, String processQuality, BigDecimal totalRequestedAmount,
BigDecimal totalApprovedAmount) {
return new GroupPrequalificationData(id, productName, prequalificationNumber, agencyName, portfolioName, centerName, groupName,
addedBy, createdAt, status, comments, groupId, null, null, null, null, null, agencyId, centerId, productId, facilitatorId,
facilitatorName, greenValidationCount, yellowValidationCount, orangeValidationCount, redValidationCount,
prequalilficationTimespan, lastPrequalificationStatus, statusChangedBy, statusChangedOn, processType, processQuality);
prequalilficationTimespan, lastPrequalificationStatus, statusChangedBy, statusChangedOn, processType, processQuality,
totalRequestedAmount, totalApprovedAmount);
}

public void updateMembers(Collection<MemberPrequalificationData> groupMembers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class MemberPrequalificationData {
private final LocalDate dob;
private final String workWithPuente;
private final BigDecimal requestedAmount;
private final BigDecimal approvedAmount;
private EnumOptionData status;
private final Long blacklistCount;
private final Long activeBlacklistCount;
Expand All @@ -55,7 +56,8 @@ public MemberPrequalificationData(final Long id, final String name, final String
final BigDecimal requestedAmount, final EnumOptionData status, Long blacklistCount, BigDecimal totalLoanAmount,
BigDecimal totalLoanBalance, BigDecimal totalGuaranteedLoanBalance, Long noOfCycles, Long additionalCreditsCount,
BigDecimal additionalCreditsSum, final Long activeBlacklistCount, final Long inActiveBlacklistCount, Long greenValidationCount,
Long yellowValidationCount, Long orangeValidationCount, Long redValidationCount, EnumOptionData bureauCheckStatus) {
Long yellowValidationCount, Long orangeValidationCount, Long redValidationCount, EnumOptionData bureauCheckStatus,
BigDecimal approvedAmount) {
this.id = id;
this.name = name;
this.dpi = dpi;
Expand All @@ -77,17 +79,18 @@ public MemberPrequalificationData(final Long id, final String name, final String
this.orangeValidationCount = orangeValidationCount;
this.redValidationCount = redValidationCount;
this.bureauCheckStatus = bureauCheckStatus;
this.approvedAmount = approvedAmount;
}

public static MemberPrequalificationData instance(final Long id, final String name, final String dpi, final LocalDate dob,
final String workWithPuente, final BigDecimal requestedAmount, final EnumOptionData status, Long blacklistCount,
BigDecimal totalLoanAmount, BigDecimal totalLoanBalance, BigDecimal totalGuaranteedLoanBalance, Long noOfCycles,
Long additionalCreditsCount, BigDecimal additionalCreditsSum, final Long activeBlacklistCount,
final Long inActiveBlacklistCount, final Long greenValidationCount, final Long yellowValidationCount,
final Long orangeValidationCount, final Long redValidationCount, EnumOptionData bureauCheckStatus) {
final Long orangeValidationCount, final Long redValidationCount, EnumOptionData bureauCheckStatus, BigDecimal approvedAmount) {
return new MemberPrequalificationData(id, name, dpi, dob, workWithPuente, requestedAmount, status, blacklistCount, totalLoanAmount,
totalLoanBalance, totalGuaranteedLoanBalance, noOfCycles, additionalCreditsCount, additionalCreditsSum,
activeBlacklistCount, inActiveBlacklistCount, greenValidationCount, yellowValidationCount, orangeValidationCount,
redValidationCount, bureauCheckStatus);
redValidationCount, bureauCheckStatus, approvedAmount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public class PrequalificationGroupMember extends AbstractPersistableCustom {
@Column(name = "requested_amount", nullable = false)
private BigDecimal requestedAmount;

@Column(name = "approved_amount", nullable = false)
private BigDecimal approvedAmount;

@Column(name = "created_at")
private LocalDateTime createdAt;

Expand Down Expand Up @@ -159,7 +162,15 @@ public Map<String, Object> update(JsonCommand command) {
final String newValue = command.stringValueOfParameterNamed(PrequalificatoinApiConstants.memberWorkWithPuenteParamName);
actualChanges.put(PrequalificatoinApiConstants.memberWorkWithPuenteParamName, newValue);
}
if (command.isChangeInBigDecimalParameterNamed(PrequalificatoinApiConstants.approvedAmountParamName, this.approvedAmount)) {
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(PrequalificatoinApiConstants.approvedAmountParamName);
actualChanges.put(PrequalificatoinApiConstants.approvedAmountParamName, newValue);
}

return actualChanges;
}

public void updateApprovedAmount(BigDecimal newValue) {
this.approvedAmount = newValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.organisation.prequalification.exception;

import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;

/**
* A {@link RuntimeException} thrown when client is already blacklisted.
*/
public class PrequalificationStatusNotChangedException extends AbstractPlatformResourceNotFoundException {

public PrequalificationStatusNotChangedException(String status) {
super("error.msg.group.prequalification.status.not.changed", "Group Prequalificaiton status " + status + " was not changed.", status);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.organisation.prequalification.handler;

import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.organisation.prequalification.service.PrequalificationWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@CommandType(entity = "PREQUALIFICATIONMEMBER", action = "UPDATE")
public class EditMemberPreQualificationCommandHandler implements NewCommandSourceHandler {

private final PrequalificationWritePlatformService prequalificationWritePlatformService;

@Autowired
public EditMemberPreQualificationCommandHandler(final PrequalificationWritePlatformService prequalificationWritePlatformService) {
this.prequalificationWritePlatformService = prequalificationWritePlatformService;
}

@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {

return this.prequalificationWritePlatformService.updatePrequalificationGroupMember(command.entityId(), command);
}
}
Loading

0 comments on commit 5b43952

Please sign in to comment.