From 6a665dbd7f5cf1da087169a9057b0e009b6f7903 Mon Sep 17 00:00:00 2001 From: Muhimbura Brian Mart Date: Wed, 24 Jul 2024 20:51:19 +0300 Subject: [PATCH] fix FSF-9 --- .../PortfolioOfficeNotFoundException.java | 30 +++++++++++++++++++ ...WritePlatformServiceJpaRepositoryImpl.java | 11 ++++++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 fineract-provider/src/main/java/org/apache/fineract/portfolio/group/exception/PortfolioOfficeNotFoundException.java diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/exception/PortfolioOfficeNotFoundException.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/exception/PortfolioOfficeNotFoundException.java new file mode 100644 index 00000000000..80eb03bda3c --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/exception/PortfolioOfficeNotFoundException.java @@ -0,0 +1,30 @@ +/** + * 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.portfolio.group.exception; + +import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException; + +public class PortfolioOfficeNotFoundException extends AbstractPlatformDomainRuleException { + + public PortfolioOfficeNotFoundException(final String potfolioOffice) { + super("error.msg.portfolio.office.not.found", + "The Portfolio with name `" + potfolioOffice + "` Does not have a matching office created. First created the office", potfolioOffice); + } + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java index d3cfa8d812f..3c5eaef73af 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java @@ -101,6 +101,7 @@ import org.apache.fineract.portfolio.group.exception.GroupMustBePendingToBeDeletedException; import org.apache.fineract.portfolio.group.exception.InvalidGroupLevelException; import org.apache.fineract.portfolio.group.exception.InvalidGroupStateTransitionException; +import org.apache.fineract.portfolio.group.exception.PortfolioOfficeNotFoundException; import org.apache.fineract.portfolio.group.exception.PrequalificationMappedException; import org.apache.fineract.portfolio.group.serialization.GroupingTypesDataValidator; import org.apache.fineract.portfolio.loanaccount.domain.Loan; @@ -1142,6 +1143,14 @@ public CommandProcessingResult generateCentersByPortfolio(Portfolio portfolio) { // set values to generate the centers final Office office = portfolio.getParentOffice(); + + String portfolioOfficeQuery = "SELECT id from m_office where name=?"; + List portfolioIds = jdbcTemplate.queryForList(portfolioOfficeQuery, Long.class, portfolio.getName()); + if (portfolioIds.size()<=0) { + throw new PortfolioOfficeNotFoundException(portfolio.getName()); + } + Office portfolioOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(portfolioIds.get(0)); +// Office portfolioOffice = office.getParent(); final boolean active = true; final LocalDate activationDate = DateUtils.getLocalDateOfTenant(); final LocalDate submittedOnDate = DateUtils.getLocalDateOfTenant(); @@ -1157,7 +1166,7 @@ public CommandProcessingResult generateCentersByPortfolio(Portfolio portfolio) { final Integer meetingStart = rangeTemplateData.getStartDay(); final Integer meetingEnd = rangeTemplateData.getEndDay(); - Group newCenter = Group.assembleNewCenterFrom(office, groupLevel, centerName, active, activationDate, submittedOnDate, + Group newCenter = Group.assembleNewCenterFrom(portfolioOffice, groupLevel, centerName, active, activationDate, submittedOnDate, currentUser, meetingStartTime, meetingEndTime, portfolio, meetingStart, meetingEnd, meetingDayValue); this.groupRepository.saveAndFlush(newCenter);