Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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 @@ -29,7 +29,6 @@
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import jakarta.persistence.UniqueConstraint;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -135,9 +134,6 @@ public class Client extends AbstractAuditableWithUTCDateTimeCustom<Long> {
@JoinTable(name = "m_group_client", joinColumns = @JoinColumn(name = "client_id"), inverseJoinColumns = @JoinColumn(name = "group_id"))
private Set<Group> groups;

@Transient
private boolean accountNumberRequiresAutoGeneration = false;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "closure_reason_cv_id")
private CodeValue closureReason;
Expand Down Expand Up @@ -237,7 +233,6 @@ private Client(final AppUser currentUser, final ClientStatus status, final Offic

if (StringUtils.isBlank(accountNo)) {
this.accountNumber = new RandomPasswordGenerator(19).generate();
this.accountNumberRequiresAutoGeneration = true;
} else {
this.accountNumber = accountNo;
}
Expand Down Expand Up @@ -327,21 +322,12 @@ public void validateUpdate() {

}

public boolean isAccountNumberRequiresAutoGeneration() {
return this.accountNumberRequiresAutoGeneration;
}

public void setAccountNumberRequiresAutoGeneration(final boolean accountNumberRequiresAutoGeneration) {
this.accountNumberRequiresAutoGeneration = accountNumberRequiresAutoGeneration;
}

public boolean identifiedBy(final Long clientId) {
return getId().equals(clientId);
}

public void updateAccountNo(final String accountIdentifier) {
this.accountNumber = accountIdentifier;
this.accountNumberRequiresAutoGeneration = false;
}

public void activate(final AppUser currentUser, final DateTimeFormatter formatter, final LocalDate activationLocalDate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.codes.domain.CodeValue;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
Expand All @@ -57,6 +58,8 @@
import org.apache.fineract.useradministration.domain.AppUser;

@Entity
@Getter
@Setter
@Table(name = "m_group")
public final class Group extends AbstractPersistableCustom<Long> {

Expand Down Expand Up @@ -130,9 +133,6 @@ public final class Group extends AbstractPersistableCustom<Long> {
@Column(name = "account_no", length = 20, unique = true, nullable = false)
private String accountNumber;

@Transient
private boolean accountNumberRequiresAutoGeneration = false;

@OneToMany(mappedBy = "group", cascade = CascadeType.REMOVE)
private Set<GroupRole> groupRole;

Expand Down Expand Up @@ -166,6 +166,12 @@ private Group(final Office office, final Staff staff, final Group parent, final

final List<ApiParameterError> dataValidationErrors = new ArrayList<>();

if (StringUtils.isBlank(accountNo)) {
this.accountNumber = new RandomPasswordGenerator(19).generate();
} else {
this.accountNumber = accountNo;
}

this.office = office;
this.staff = staff;
this.groupLevel = groupLevel;
Expand All @@ -175,10 +181,7 @@ private Group(final Office office, final Staff staff, final Group parent, final
this.parent.addChild(this);
}

if (StringUtils.isBlank(accountNo)) {
this.accountNumber = new RandomPasswordGenerator(19).generate();
this.accountNumberRequiresAutoGeneration = true;
} else {
if (!StringUtils.isBlank(accountNo)) {
this.accountNumber = accountNo;
}

Expand Down Expand Up @@ -339,14 +342,6 @@ public Map<String, Object> update(final JsonCommand command) {
return actualChanges;
}

public LocalDate getSubmittedOnDate() {
return this.submittedOnDate;
}

public LocalDate getActivationDate() {
return this.activationDate;
}

public List<String> associateClients(final Set<Client> clientMembersSet) {
final List<String> differences = new ArrayList<>();
for (final Client client : clientMembersSet) {
Expand Down Expand Up @@ -434,30 +429,6 @@ public void unassignStaff() {
this.staff = null;
}

public GroupLevel getGroupLevel() {
return this.groupLevel;
}

public Staff getStaff() {
return this.staff;
}

public void setStaff(final Staff staff) {
this.staff = staff;
}

public Group getParent() {
return this.parent;
}

public void setParent(final Group parent) {
this.parent = parent;
}

public Office getOffice() {
return this.office;
}

public boolean isCenter() {
return this.groupLevel.isCenter();
}
Expand Down Expand Up @@ -689,10 +660,6 @@ private void throwExceptionIfErrors(final List<ApiParameterError> dataValidation
}
}

public Set<Client> getClientMembers() {
return this.clientMembers;
}

// StaffAssignmentHistory[during center creation]
public void captureStaffHistoryDuringCenterCreation(final Staff newStaff, final LocalDate assignmentDate) {
if (this.isCenter() && this.isActive() && staff != null) {
Expand Down Expand Up @@ -732,21 +699,8 @@ private StaffAssignmentHistory findLatestIncompleteHistoryRecord() {
return latestRecordWithNoEndDate;
}

public boolean isAccountNumberRequiresAutoGeneration() {
return this.accountNumberRequiresAutoGeneration;
}

public void setAccountNumberRequiresAutoGeneration(final boolean accountNumberRequiresAutoGeneration) {
this.accountNumberRequiresAutoGeneration = accountNumberRequiresAutoGeneration;
}

public void updateAccountNo(final String accountIdentifier) {
this.accountNumber = accountIdentifier;
this.accountNumberRequiresAutoGeneration = false;
}

public void setGroupMembers(List<Group> groupMembers) {
this.groupMembers = groupMembers;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,22 @@ public CommandProcessingResult createClient(final JsonCommand command) {
savingsProductId, savingsAccountId, dataOfBirth, gender, clientType, clientClassification, legalForm.getValue(),
isStaff);

// Account Number generation
this.clientRepository.saveAndFlush(newClient);
if (StringUtils.isBlank(accountNo)) {
AccountNumberFormat accountNumberFormat = this.accountNumberFormatRepository.findByAccountType(EntityAccountType.CLIENT);
newClient.updateAccountNo(accountNumberGenerator.generate(newClient, accountNumberFormat));
this.clientRepository.saveAndFlush(newClient);
}

boolean rollbackTransaction = false;
if (newClient.isActive()) {
validateParentGroupRulesBeforeClientActivation(newClient);
runEntityDatatableCheck(newClient.getId(), newClient.getLegalForm());
final CommandWrapper commandWrapper = new CommandWrapperBuilder().activateClient(null).build();
rollbackTransaction = this.commandProcessingService.validateRollbackCommand(commandWrapper, currentUser);
}

this.clientRepository.saveAndFlush(newClient);
if (newClient.isAccountNumberRequiresAutoGeneration()) {
AccountNumberFormat accountNumberFormat = this.accountNumberFormatRepository.findByAccountType(EntityAccountType.CLIENT);
newClient.updateAccountNo(accountNumberGenerator.generate(newClient, accountNumberFormat));
this.clientRepository.saveAndFlush(newClient);
}

final Locale locale = command.extractLocale();
final DateTimeFormatter fmt = DateTimeFormatter.ofPattern(command.dateFormat()).withLocale(locale);
Expand Down Expand Up @@ -1101,4 +1102,5 @@ public CommandProcessingResult undoWithdrawal(Long entityId, JsonCommand command
.withEntityExternalId(client.getExternalId()) //
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Set;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandProcessingService;
Expand Down Expand Up @@ -186,17 +187,18 @@ private CommandProcessingResult createGroupingType(final JsonCommand command, fi
rollbackTransaction = this.commandProcessingService.validateRollbackCommand(commandWrapper, currentUser);
}

// pre-save to generate id for use in group hierarchy
this.groupRepository.save(newGroup);

// Account Number generation
if (StringUtils.isBlank(accountNo)) {
generateAccountNumber(newGroup);
}

/*
* Generate hierarchy for a new center/group and all the child groups if they exist
*/
newGroup.generateHierarchy();

/* Generate account number if required */
generateAccountNumberIfRequired(newGroup);

this.groupRepository.saveAndFlush(newGroup);
newGroup.captureStaffHistoryDuringCenterCreation(staff, activationDate);

Expand Down Expand Up @@ -229,20 +231,17 @@ private CommandProcessingResult createGroupingType(final JsonCommand command, fi
}
}

private void generateAccountNumberIfRequired(Group newGroup) {
if (newGroup.isAccountNumberRequiresAutoGeneration()) {
EntityAccountType entityAccountType = null;
AccountNumberFormat accountNumberFormat = null;
if (newGroup.isCenter()) {
entityAccountType = EntityAccountType.CENTER;
accountNumberFormat = this.accountNumberFormatRepository.findByAccountType(entityAccountType);
newGroup.updateAccountNo(this.accountNumberGenerator.generateCenterAccountNumber(newGroup, accountNumberFormat));
} else {
entityAccountType = EntityAccountType.GROUP;
accountNumberFormat = this.accountNumberFormatRepository.findByAccountType(entityAccountType);
newGroup.updateAccountNo(this.accountNumberGenerator.generateGroupAccountNumber(newGroup, accountNumberFormat));
}

private void generateAccountNumber(Group newGroup) {
EntityAccountType entityAccountType = null;
AccountNumberFormat accountNumberFormat = null;
if (newGroup.isCenter()) {
entityAccountType = EntityAccountType.CENTER;
accountNumberFormat = this.accountNumberFormatRepository.findByAccountType(entityAccountType);
newGroup.updateAccountNo(this.accountNumberGenerator.generateCenterAccountNumber(newGroup, accountNumberFormat));
} else {
entityAccountType = EntityAccountType.GROUP;
accountNumberFormat = this.accountNumberFormatRepository.findByAccountType(entityAccountType);
newGroup.updateAccountNo(this.accountNumberGenerator.generateGroupAccountNumber(newGroup, accountNumberFormat));
}
}

Expand Down
Loading