Skip to content

Commit

Permalink
Merge pull request #1308 from fiterlatam/fix/FSF-73
Browse files Browse the repository at this point in the history
Fix/fsf 73
  • Loading branch information
BrianMuhimbura authored Nov 21, 2024
2 parents 8b9110b + 1fa5bb2 commit e8425bb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public interface GroupRepository extends JpaRepository<Group, Long>, JpaSpecific

Optional<Group> findByPrequalificationGroup(PrequalificationGroup prequalificationGroup);

Optional<Group> findByNameAndGroupLevel(String name, GroupLevel type);

// Collection<Group> findByPrequalificationGroup(PrequalificationGroup prequalificationGroup);

String RETRIEVE_SUBMITTED_ON_DATE = "select g.submittedOnDate from Group g where g.id = :groupId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.fineract.portfolio.group.domain;

import java.time.LocalDate;
import java.util.Optional;
import org.apache.fineract.organisation.office.domain.Office;
import org.apache.fineract.organisation.prequalification.domain.PrequalificationGroup;
import org.apache.fineract.portfolio.group.exception.GroupNotFoundException;
Expand All @@ -44,6 +45,10 @@ public Group findOneWithNotFoundDetection(final Long id) {
return this.repository.findById(id).orElseThrow(() -> new GroupNotFoundException(id));
}

public Optional<Group> findByNameAndGroupLevel(final String name, final GroupLevel groupLevel) {
return this.repository.findByNameAndGroupLevel(name, groupLevel);
}

public Group findOneWithPrequalificationIdNotFoundDetection(final PrequalificationGroup prequalificationGroup) {
return this.repository.findByPrequalificationGroup(prequalificationGroup)
.orElseThrow(() -> new GroupNotFoundException(prequalificationGroup.getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ public GroupExistsInCenterException(final Long centerId, final Long groupId) {
"Group with identifier " + groupId + " is already exists in Center with identifier " + centerId, groupId, centerId);
}

public GroupExistsInCenterException(final Long centerId, final String groupName) {
super("error.msg.group.is.already.member.of.center",
"Group with name " + groupName + " already exists in Center with identifier " + centerId, groupName, centerId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.persistence.PersistenceException;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -95,6 +96,7 @@
import org.apache.fineract.portfolio.group.domain.GroupRepositoryWrapper;
import org.apache.fineract.portfolio.group.domain.GroupTypes;
import org.apache.fineract.portfolio.group.exception.GroupAccountExistsException;
import org.apache.fineract.portfolio.group.exception.GroupExistsInCenterException;
import org.apache.fineract.portfolio.group.exception.GroupHasNoStaffException;
import org.apache.fineract.portfolio.group.exception.GroupMeetingTimeCollisionException;
import org.apache.fineract.portfolio.group.exception.GroupMemberCountNotInPermissibleRangeException;
Expand Down Expand Up @@ -177,6 +179,11 @@ private CommandProcessingResult createGroupingType(final JsonCommand command, fi
final LocalDate activationDate = command.localDateValueOfParameterNamed(GroupingTypesApiConstants.activationDateParamName);
final GroupLevel groupLevel = this.groupLevelRepository.findById(groupingType.getId()).orElse(null);

Optional<Group> existingGroupName = this.groupRepository.findByNameAndGroupLevel(name, groupLevel);
if (existingGroupName.isPresent()) {
Group oldGroup = existingGroupName.get();
throw new GroupExistsInCenterException(oldGroup.getParent().getId(), oldGroup.getName());
}
validateOfficeOpeningDateisAfterGroupOrCenterOpeningDate(groupOffice, groupLevel, activationDate);

Staff staff = null;
Expand Down

0 comments on commit e8425bb

Please sign in to comment.