Fixing some code to be compatible with Spring update

This commit is contained in:
Angel Cajas
2020-03-13 17:15:25 +01:00
committed by Michael Vorburger ⛑️
parent c342f5b43d
commit e2f5c95034
2 changed files with 8 additions and 15 deletions
@@ -36,19 +36,14 @@ public class RateRepositoryWrapper {
}
public Rate findOneWithNotFoundDetection(final Long rateId) {
final Rate rate = this.repository.findOne(rateId);
if (rate == null) {
throw new RateNotFoundException(rateId);
}
final Rate rate = this.repository.findById(rateId).orElseThrow(() -> new RateNotFoundException(rateId));
return rate;
}
public List<Rate> findMultipleWithNotFoundDetection(final List<Long> rateIds) {
List<Rate> rates = new ArrayList<>();
if (rateIds != null && !rateIds.isEmpty()) {
final List<Rate> foundRates = this.repository.findAll(rateIds);
final List<Rate> foundRates = this.repository.findAllById(rateIds);
for (Long rateId : rateIds) {
Boolean found = false;
for (Rate foundRate : foundRates) {
@@ -34,6 +34,7 @@ import org.apache.fineract.portfolio.rate.exception.RateNotFoundException;
import org.apache.fineract.portfolio.rate.serialization.RateDefinitionCommandFromApiJsonDeserializer;
import org.apache.fineract.useradministration.domain.AppUser;
import org.apache.fineract.useradministration.domain.AppUserRepository;
import org.apache.fineract.useradministration.exception.UserNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -73,7 +74,7 @@ public class RateWriteServiceImpl implements RateWriteService {
final Long approveUserId = command.longValueOfParameterNamed(approveUserIdParamName);
AppUser approveUser = null;
if (approveUserId != null) {
approveUser = this.appUserRepository.findOne(approveUserId);
approveUser = this.appUserRepository.findById(approveUserId).orElseThrow(() -> new UserNotFoundException(approveUserId));
}
final Rate rate = Rate.fromJson(command, approveUser);
@@ -98,20 +99,17 @@ public class RateWriteServiceImpl implements RateWriteService {
try {
this.context.authenticatedUser();
final Rate rateToUpdate = this.rateRepository.findOne(rateId);
if (rateToUpdate == null) {
throw new RateNotFoundException(rateId);
}
final Rate rateToUpdate = this.rateRepository.findById(rateId).orElseThrow(() -> new RateNotFoundException(rateId));
final Map<String, Object> changes = rateToUpdate.update(command);
this.fromApiJsonDeserializer.validateForUpdate(command.json());
if (changes.containsKey(approveUserIdParamName)) {
final Long newValue = (Long) changes.get(approveUserIdParamName);
final Long newApproveUserId = (Long) changes.get(approveUserIdParamName);
AppUser newApproveUser = null;
if (newValue != null) {
newApproveUser = this.appUserRepository.findOne(newValue);
if (newApproveUserId != null) {
newApproveUser = this.appUserRepository.findById(newApproveUserId).orElseThrow(() -> new UserNotFoundException(newApproveUserId));
}
rateToUpdate.setApproveUser(newApproveUser);
}