blob: a85515b7c0f89af6cab4611e765edece50431755 [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.shareaccounts.jobs.postdividentsforshares;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException;
import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountDividendReadPlatformService;
import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountSchedularService;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
@Slf4j
@RequiredArgsConstructor
public class PostDividentsForSharesTasklet implements Tasklet {
private final ShareAccountDividendReadPlatformService shareAccountDividendReadPlatformService;
private final ShareAccountSchedularService shareAccountSchedularService;
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
List<Throwable> exceptions = new ArrayList<>();
List<Map<String, Object>> dividendDetails = shareAccountDividendReadPlatformService.retriveDividendDetailsForPostDividents();
for (Map<String, Object> dividendMap : dividendDetails) {
Long id;
Long savingsId;
if (dividendMap.get("id") instanceof BigInteger) {
id = ((BigInteger) dividendMap.get("id")).longValue();
savingsId = ((BigInteger) dividendMap.get("savingsAccountId")).longValue();
} else {
id = (Long) dividendMap.get("id");
savingsId = (Long) dividendMap.get("savingsAccountId");
}
try {
shareAccountSchedularService.postDividend(id, savingsId);
} catch (final PlatformApiDataValidationException e) {
exceptions.add(e);
final List<ApiParameterError> errors = e.getErrors();
for (final ApiParameterError error : errors) {
log.error(
"Post Dividends to savings failed due to ApiParameterError for Divident detail Id: {} and savings Id: {} with message: {}",
id, savingsId, error.getDeveloperMessage(), e);
}
} catch (final Exception e) {
log.error("Post Dividends to savings failed for Divident detail Id: {} and savings Id: {}", id, savingsId, e);
exceptions.add(e);
}
}
if (!exceptions.isEmpty()) {
throw new JobExecutionException(exceptions);
}
return RepeatStatus.FINISHED;
}
}