Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,24 @@ public CommandWrapperBuilder updateGuarantor(final Long loanId, final Long guara
return this;
}

public CommandWrapperBuilder approveGuarantor(final Long loanId, final Long guarantorId) {
this.actionName = "APPROVE";
this.entityName = "GUARANTOR";
this.entityId = guarantorId;
this.loanId = loanId;
this.href = "/loans/" + loanId + "/guarantors/" + guarantorId + "?command=approve";
return this;
}

public CommandWrapperBuilder rejectGuarantor(final Long loanId, final Long guarantorId) {
this.actionName = "REJECT";
this.entityName = "GUARANTOR";
this.entityId = guarantorId;
this.loanId = loanId;
this.href = "/loans/" + loanId + "/guarantors/" + guarantorId + "?command=reject";
return this;
}

public CommandWrapperBuilder deleteGuarantor(final Long loanId, final Long guarantorId, final Long guarantorFundingId) {
this.actionName = "DELETE";
this.entityName = "GUARANTOR";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,17 @@ public static class FineractTemplateProperties {

private boolean regexWhitelistEnabled;
private List<String> regexWhitelist;

private InternalUser internalUser;

@Getter
@Setter
public static class InternalUser {

private String username;
private String password;

}
}

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
*/
package org.apache.fineract.infrastructure.crypt.repository;

import java.util.Optional;

import org.apache.fineract.infrastructure.crypt.domain.EncryptionKey;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

public interface EncryptionKeyRepository
extends JpaRepository<EncryptionKey, Long>, JpaSpecificationExecutor<EncryptionKey> {

EncryptionKey findByKeyType(String keyType);
Optional<EncryptionKey> findByKeyType(String keyType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.time.Duration;
import java.util.Base64;
import java.util.Optional;

import jakarta.inject.Singleton;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
Expand Down Expand Up @@ -59,12 +60,12 @@ public EncryptionKeyStoreServiceImpl(

private void storeKey(String type, EncryptionKeyPair key) {

EncryptionKey entity = encryptionKeyRepository.findByKeyType(type);

if (entity == null) {
entity = new EncryptionKey();
entity.setKeyType(type);
}
EncryptionKey entity = encryptionKeyRepository.findByKeyType(type)
.orElseGet(() -> {
EncryptionKey newEntity = new EncryptionKey();
newEntity.setKeyType(type);
return newEntity;
});

entity.setPublicKey(
Base64.getEncoder().encodeToString(key.getPublicKey()));
Expand Down Expand Up @@ -101,18 +102,13 @@ private EncryptionKeyPair retrieveValidKey(String type){

private EncryptionKeyPair getKeys(String type) {

EncryptionKey entity = encryptionKeyRepository.findByKeyType(type);

if (entity == null) {
return null;
}

return new EncryptionKeyPair(
Base64.getDecoder().decode(entity.getPrivateKey()),
Base64.getDecoder().decode(entity.getPublicKey()),
entity.getCreatedAt(),
entity.getVersion()
);
return encryptionKeyRepository.findByKeyType(type)
.map(entity -> new EncryptionKeyPair(
Base64.getDecoder().decode(entity.getPrivateKey()),
Base64.getDecoder().decode(entity.getPublicKey()),
entity.getCreatedAt(),
entity.getVersion()))
.orElse(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,37 @@ public String updateGuarantor(@PathParam("loanId") final Long loanId, @PathParam
return this.apiJsonSerializerService.serialize(result);
}

@POST
@Path("{guarantorId}")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we dont need to create these

@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String guarantorCommand(@PathParam("loanId") final Long loanId,
@PathParam("guarantorId") final Long guarantorId,
@QueryParam("command") final String command,
final String jsonRequestBody) {

CommandWrapper commandRequest = null;

if ("approve".equalsIgnoreCase(command)) {
commandRequest = new CommandWrapperBuilder()
.approveGuarantor(loanId, guarantorId)
.withJson(jsonRequestBody)
.build();
} else if ("reject".equalsIgnoreCase(command)) {
commandRequest = new CommandWrapperBuilder()
.rejectGuarantor(loanId, guarantorId)
.withJson(jsonRequestBody)
.build();
} else {
throw new IllegalArgumentException("Unsupported command: " + command);
}

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

return this.apiJsonSerializerService.serialize(result);
}

@DELETE
@Path("{guarantorId}")
@Consumes({ MediaType.APPLICATION_JSON })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class GuarantorData {
private final LocalDate dob;
private final Collection<GuarantorFundingData> guarantorFundingDetails;
private final boolean status;
private final Integer approvalStatus;

// template
@SuppressWarnings("unused")
Expand Down Expand Up @@ -119,6 +120,7 @@ private GuarantorData(Integer guarantorTypeId, Integer clientRelationshipTypeId,
this.comment = null;
this.guarantorFundingDetails = null;
this.status = false;
this.approvalStatus = null;
this.guarantorTypeOptions = null;
this.allowedClientRelationshipTypes = null;
this.accountLinkingOptions = null;
Expand All @@ -129,7 +131,7 @@ public static GuarantorData template(final List<EnumOptionData> guarantorTypeOpt
final Collection<GuarantorFundingData> guarantorFundingDetails = null;
final boolean status = false;
return new GuarantorData(null, null, null, null, GuarantorEnumerations.guarantorType(GuarantorType.CUSTOMER), null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, status, guarantorFundingDetails,
null, null, null, null, null, null, null, null, null, null, null, null, status, null, guarantorFundingDetails,
guarantorTypeOptions, allowedClientRelationshipTypes, accountLinkingOptions);
}

Expand All @@ -139,30 +141,30 @@ public static GuarantorData templateOnTop(final GuarantorData guarantorData, fin
guarantorData.guarantorType, guarantorData.firstname, guarantorData.lastname, guarantorData.dob, guarantorData.addressLine1,
guarantorData.addressLine2, guarantorData.city, guarantorData.state, guarantorData.zip, guarantorData.country,
guarantorData.mobileNumber, guarantorData.housePhoneNumber, guarantorData.comment, guarantorData.officeName,
guarantorData.joinedDate, guarantorData.externalId, guarantorData.status, guarantorData.guarantorFundingDetails,
guarantorData.joinedDate, guarantorData.externalId, guarantorData.status, guarantorData.approvalStatus, guarantorData.guarantorFundingDetails,
guarantorTypeOptions, allowedClientRelationshipTypes, accountLinkingOptions);
}

public static GuarantorData mergeClientData(final ClientData clientData, final GuarantorData guarantorData) {
return new GuarantorData(guarantorData.id, guarantorData.loanId, guarantorData.clientRelationshipType, guarantorData.entityId,
guarantorData.guarantorType, clientData.getFirstname(), clientData.getLastname(), null, null, null, null, null, null, null,
null, null, null, clientData.getOfficeName(), clientData.getActivationDate(), clientData.getExternalId().getValue(),
guarantorData.status, guarantorData.guarantorFundingDetails, null, guarantorData.allowedClientRelationshipTypes,
guarantorData.status, guarantorData.approvalStatus, guarantorData.guarantorFundingDetails, null, guarantorData.allowedClientRelationshipTypes,
guarantorData.accountLinkingOptions);
}

public static GuarantorData mergeStaffData(final StaffData staffData, final GuarantorData guarantorData) {
return new GuarantorData(guarantorData.id, guarantorData.loanId, guarantorData.clientRelationshipType, guarantorData.entityId,
guarantorData.guarantorType, staffData.getFirstname(), staffData.getLastname(), null, null, null, null, null, null, null,
null, null, null, staffData.getOfficeName(), null, null, guarantorData.status, guarantorData.guarantorFundingDetails, null,
null, null, null, staffData.getOfficeName(), null, null, guarantorData.status, guarantorData.approvalStatus, guarantorData.guarantorFundingDetails, null,
guarantorData.allowedClientRelationshipTypes, guarantorData.accountLinkingOptions);
}

public GuarantorData(final Long id, final Long loanId, final CodeValueData clientRelationshipType, final Long entityId,
final EnumOptionData guarantorType, final String firstname, final String lastname, final LocalDate dob,
final String addressLine1, final String addressLine2, final String city, final String state, final String zip,
final String country, final String mobileNumber, final String housePhoneNumber, final String comment, final String officeName,
final LocalDate joinedDate, final String externalId, final boolean status,
final LocalDate joinedDate, final String externalId, final boolean status, final Integer approvalStatus,
Collection<GuarantorFundingData> guarantorFundingDetails, final List<EnumOptionData> guarantorTypeOptions,
final Collection<CodeValueData> allowedClientRelationshipTypes, final Collection<PortfolioAccountData> accountLinkingOptions) {
this.id = id;
Expand All @@ -186,6 +188,7 @@ public GuarantorData(final Long id, final Long loanId, final CodeValueData clien
this.joinedDate = joinedDate;
this.externalId = externalId;
this.status = status;
this.approvalStatus = approvalStatus;
this.guarantorFundingDetails = guarantorFundingDetails;
this.guarantorTypeOptions = guarantorTypeOptions;
this.allowedClientRelationshipTypes = allowedClientRelationshipTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public class Guarantor extends AbstractPersistableCustom {
@Column(name = "is_active", nullable = false)
private boolean active;

@Column(name = "approval_status", nullable = false)
private Integer approvalStatus;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "guarantor", orphanRemoval = true, fetch = FetchType.EAGER)
private List<GuarantorFundingDetails> guarantorFundDetails = new ArrayList<>();

Expand All @@ -106,7 +109,7 @@ private Guarantor(final Loan loan, final CodeValue clientRelationshipType, final
final String firstname, final String lastname, final LocalDate dateOfBirth, final String addressLine1,
final String addressLine2, final String city, final String state, final String country, final String zip,
final String housePhoneNumber, final String mobilePhoneNumber, final String comment, final boolean active,
final List<GuarantorFundingDetails> guarantorFundDetails) {
final Integer approvalStatus,final List<GuarantorFundingDetails> guarantorFundDetails) {
this.loan = loan;
this.clientRelationshipType = clientRelationshipType;
this.gurantorType = gurantorType;
Expand All @@ -124,6 +127,7 @@ private Guarantor(final Loan loan, final CodeValue clientRelationshipType, final
this.mobilePhoneNumber = StringUtils.defaultIfEmpty(mobilePhoneNumber, null);
this.comment = StringUtils.defaultIfEmpty(comment, null);
this.active = active;
this.approvalStatus = approvalStatus;
this.guarantorFundDetails.addAll(guarantorFundDetails);
}

Expand All @@ -132,6 +136,7 @@ public static Guarantor fromJson(final Loan loan, final CodeValue clientRelation
final Integer gurantorType = command.integerValueSansLocaleOfParameterNamed(GuarantorJSONinputParams.GUARANTOR_TYPE_ID.getValue());
final Long entityId = command.longValueOfParameterNamed(GuarantorJSONinputParams.ENTITY_ID.getValue());
final boolean active = true;
final Integer approvalStatus = GuarantorApprovalStatus.PENDING.getValue();
if (GuarantorType.EXTERNAL.getValue().equals(gurantorType)) {
final String firstname = command.stringValueOfParameterNamed(GuarantorJSONinputParams.FIRSTNAME.getValue());
final String lastname = command.stringValueOfParameterNamed(GuarantorJSONinputParams.LASTNAME.getValue());
Expand All @@ -147,11 +152,11 @@ public static Guarantor fromJson(final Loan loan, final CodeValue clientRelation
final String comment = command.stringValueOfParameterNamed(GuarantorJSONinputParams.COMMENT.getValue());

return new Guarantor(loan, clientRelationshipType, gurantorType, entityId, firstname, lastname, dateOfBirth, addressLine1,
addressLine2, city, state, country, zip, housePhoneNumber, mobilePhoneNumber, comment, active, fundingDetails);
addressLine2, city, state, country, zip, housePhoneNumber, mobilePhoneNumber, comment, active, approvalStatus, fundingDetails);
}

return new Guarantor(loan, clientRelationshipType, gurantorType, entityId, null, null, null, null, null, null, null, null, null,
null, null, null, active, fundingDetails);
null, null, null, active, approvalStatus, fundingDetails);

}

Expand Down Expand Up @@ -299,6 +304,30 @@ public void updateStatus(final boolean status) {
this.active = status;
}

public void approve() {
this.approvalStatus = GuarantorApprovalStatus.APPROVED.getValue();
}

public void reject() {
this.approvalStatus = GuarantorApprovalStatus.REJECTED.getValue();
}

public boolean isPending() {
return GuarantorApprovalStatus.fromInt(this.approvalStatus).isPending();
}

public boolean isApproved() {
return GuarantorApprovalStatus.fromInt(this.approvalStatus).isApproved();
}

public boolean isRejected() {
return GuarantorApprovalStatus.fromInt(this.approvalStatus).isRejected();
}

public Integer getApprovalStatus() {
return this.approvalStatus;
}

public void addFundingDetails(final List<GuarantorFundingDetails> fundingDetails) {
this.guarantorFundDetails.addAll(fundingDetails);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* 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.
*
* 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.portfolio.loanaccount.guarantor.domain;

/**
* Enum representation of {@link Guarantor} approval status.
*/
public enum GuarantorApprovalStatus {

INVALID(0, "guarantorApprovalStatus.invalid"), //
PENDING(100, "guarantorApprovalStatus.pending"), //
APPROVED(200, "guarantorApprovalStatus.approved"), //
REJECTED(300, "guarantorApprovalStatus.rejected");

private final Integer value;
private final String code;

public static GuarantorApprovalStatus fromInt(final Integer type) {

GuarantorApprovalStatus enumeration = GuarantorApprovalStatus.INVALID;
switch (type) {
case 100:
enumeration = GuarantorApprovalStatus.PENDING;
break;
case 200:
enumeration = GuarantorApprovalStatus.APPROVED;
break;
case 300:
enumeration = GuarantorApprovalStatus.REJECTED;
break;
}

return enumeration;
}

GuarantorApprovalStatus(final Integer value, final String code) {
this.value = value;
this.code = code;
}

public boolean hasStateOf(final GuarantorApprovalStatus state) {
return this.value.equals(state.getValue());
}

public Integer getValue() {
return this.value;
}

public String getCode() {
return this.code;
}

public boolean isPending() {
return this.value.equals(GuarantorApprovalStatus.PENDING.getValue());
}

public boolean isApproved() {
return this.value.equals(GuarantorApprovalStatus.APPROVED.getValue());
}

public boolean isRejected() {
return this.value.equals(GuarantorApprovalStatus.REJECTED.getValue());
}
}
Loading
Loading