blob: 6e8e619564eb5438720dd4b6cff9bb18457158c3 [file] [log] [blame]
/**
* 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.savings.service;
import java.util.List;
import org.apache.fineract.infrastructure.jobs.annotation.CronTarget;
import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException;
import org.apache.fineract.infrastructure.jobs.service.JobName;
import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
import org.apache.fineract.portfolio.savings.domain.SavingsAccountAssembler;
import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepository;
import org.apache.fineract.portfolio.savings.domain.SavingsAccountStatusType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SavingsSchedularServiceImpl implements SavingsSchedularService {
private final SavingsAccountAssembler savingAccountAssembler;
private final SavingsAccountWritePlatformService savingsAccountWritePlatformService;
private final SavingsAccountRepository savingAccountRepository;
@Autowired
public SavingsSchedularServiceImpl(final SavingsAccountAssembler savingAccountAssembler,
final SavingsAccountWritePlatformService savingsAccountWritePlatformService,
final SavingsAccountRepository savingAccountRepository) {
this.savingAccountAssembler = savingAccountAssembler;
this.savingsAccountWritePlatformService = savingsAccountWritePlatformService;
this.savingAccountRepository = savingAccountRepository;
}
@CronTarget(jobName = JobName.POST_INTEREST_FOR_SAVINGS)
@Override
public void postInterestForAccounts() throws JobExecutionException {
final List<SavingsAccount> savingsAccounts = this.savingAccountRepository.findSavingAccountByStatus(SavingsAccountStatusType.ACTIVE
.getValue());
StringBuffer sb = new StringBuffer();
for (final SavingsAccount savingsAccount : savingsAccounts) {
try {
this.savingAccountAssembler.assignSavingAccountHelpers(savingsAccount);
this.savingsAccountWritePlatformService.postInterest(savingsAccount);
} catch (Exception e) {
Throwable realCause = e;
if (e.getCause() != null) {
realCause = e.getCause();
}
sb.append("failed to post interest for Savings with id " + savingsAccount.getId() + " with message "
+ realCause.getMessage());
}
}
if (sb.length() > 0) { throw new JobExecutionException(sb.toString()); }
}
}