use of org.mifos.framework.components.batchjobs.exceptions.BatchJobException in project head by mifos.
the class ETLReportDWHelper method execute.
@Override
public void execute(final long timeInMillis) throws BatchJobException {
new ApplicationContextHolder();
ArrayList<String> errors = new ArrayList<String>();
ApplicationContext ach = ApplicationContextHolder.getApplicationContext();
DriverManagerDataSource ds = (DriverManagerDataSource) ach.getBean("dataSource");
DriverManagerDataSource dsDW = (DriverManagerDataSource) ach.getBean("dataSourcePentahoDW");
Pattern pat = Pattern.compile(DATA_WAREHOUSE_DB_NAME_PATTERN);
Matcher m = pat.matcher(dsDW.getUrl());
String nameOfDataBase = null;
if (m.find()) {
nameOfDataBase = m.group(6);
}
if (!nameOfDataBase.equals("")) {
try {
dsDW.getConnection();
} catch (SQLException ex) {
errors.add("Data Warehouse is not configured");
throw new BatchJobException("Data warehouse database", errors);
}
ConfigurationLocator configurationLocator = new ConfigurationLocator();
String configPath = configurationLocator.getConfigurationDirectory();
createPropertiesFileForPentahoDWReports(ds, dsDW);
String path = configPath + "/ETL/MifosDataWarehouseETL/" + FILENAME;
String jarPath = configPath + "/ETL/mifos-etl-plugin-1.0-SNAPSHOT.one-jar.jar";
String javaHome = System.getProperty("java.home") + "/bin/java";
String pathToLog = configPath + "/ETL/log";
if (File.separatorChar == '\\') {
// windows platform
javaHome = javaHome.replaceAll("/", "\\\\");
javaHome = '"' + javaHome + '"';
jarPath = jarPath.replaceAll("/", "\\\\");
path = path.replaceAll("/", "\\\\");
pathToLog = pathToLog.replaceAll("/", "\\\\");
}
PrintWriter fw = null;
try {
boolean hasErrors = false;
boolean notRun = true;
ProcessBuilder processBuilder = new ProcessBuilder(javaHome, "-jar", jarPath, path, "false", dsDW.getUsername(), dsDW.getPassword(), dsDW.getUrl());
processBuilder.redirectErrorStream(true);
Process p = processBuilder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
if (new File(pathToLog).exists()) {
new File(pathToLog).delete();
}
File file = new File(pathToLog);
fw = new PrintWriter(file);
while ((line = reader.readLine()) != null) {
fw.println(line);
if (line.matches("^ERROR.*")) {
hasErrors = true;
}
notRun = false;
}
if (notRun) {
errors.add("Data Warehouse is not configured properly");
throw new BatchJobException("Data warehouse database", errors);
}
if (hasErrors) {
errors.add("ETL error, for more details see log file: " + pathToLog);
throw new BatchJobException("ETL error", errors);
}
} catch (IOException ex) {
throw new BatchJobException(ex.getCause());
} finally {
if (fw != null) {
fw.close();
}
}
} else {
errors.add("Data Warehouse is not configured");
throw new BatchJobException("Data warehouse database", errors);
}
}
use of org.mifos.framework.components.batchjobs.exceptions.BatchJobException in project head by mifos.
the class GenerateMeetingsForCustomerAndSavingsHelper method execute.
@Override
public void execute(@SuppressWarnings("unused") final long timeInMillis) throws BatchJobException {
workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
officeCurrentAndFutureHolidays = new HashMap<Short, List<Holiday>>();
long taskStartTime = new DateTimeService().getCurrentDateTime().getMillis();
List<Integer> customerAndSavingsAccountIds = findActiveCustomerAndSavingsAccountIdsThatRequiredMeetingsToBeGenerated();
int accountCount = customerAndSavingsAccountIds.size();
if (accountCount == 0) {
return;
}
List<String> errorList = new ArrayList<String>();
int currentRecordNumber = 0;
int outputIntervalForBatchJobs = GeneralConfig.getOutputIntervalForBatchJobs();
int batchSize = GeneralConfig.getBatchSizeForBatchJobs();
// jpw - hardcoded recordCommittingSize to 500 because now only accounts that need more schedules are returned
int recordCommittingSize = 500;
infoLogBatchParameters(accountCount, outputIntervalForBatchJobs, batchSize, recordCommittingSize);
long startTime = new DateTimeService().getCurrentDateTime().getMillis();
Integer currentAccountId = null;
int updatedRecordCount = 0;
try {
StaticHibernateUtil.getSessionTL();
StaticHibernateUtil.startTransaction();
for (Integer accountId : customerAndSavingsAccountIds) {
currentRecordNumber++;
currentAccountId = accountId;
AccountBO accountBO = legacyAccountDao.getAccount(accountId);
List<Holiday> currentAndFutureHolidays = getOfficeCurrentAndFutureHolidays(accountBO.getOffice().getOfficeId());
ScheduledDateGeneration scheduleGenerationStrategy = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, currentAndFutureHolidays);
if (accountBO instanceof CustomerAccountBO) {
((CustomerAccountBO) accountBO).generateNextSetOfMeetingDates(scheduleGenerationStrategy);
updatedRecordCount++;
} else if (accountBO instanceof SavingsBO) {
((SavingsBO) accountBO).generateNextSetOfMeetingDates(workingDays, currentAndFutureHolidays);
updatedRecordCount++;
}
if (currentRecordNumber % batchSize == 0) {
StaticHibernateUtil.flushAndClearSession();
getLogger().debug("completed HibernateUtil.flushAndClearSession()");
}
if (updatedRecordCount > 0) {
if (updatedRecordCount % recordCommittingSize == 0) {
StaticHibernateUtil.commitTransaction();
StaticHibernateUtil.getSessionTL();
StaticHibernateUtil.startTransaction();
}
}
if (currentRecordNumber % outputIntervalForBatchJobs == 0) {
long time = System.currentTimeMillis();
String message = "" + currentRecordNumber + " processed, " + (accountCount - currentRecordNumber) + " remaining, " + updatedRecordCount + " updated, batch time: " + (time - startTime) + " ms";
logMessage(message);
startTime = time;
}
}
StaticHibernateUtil.commitTransaction();
long time = System.currentTimeMillis();
String message = "" + currentRecordNumber + " processed, " + (accountCount - currentRecordNumber) + " remaining, " + updatedRecordCount + " updated, batch time: " + (time - startTime) + " ms";
logMessage(message);
} catch (Exception e) {
logMessage("account " + currentAccountId.intValue() + " exception " + e.getMessage());
StaticHibernateUtil.rollbackTransaction();
errorList.add(currentAccountId.toString());
getLogger().error("Unable to generate schedules for account with ID " + currentAccountId, e);
} finally {
StaticHibernateUtil.closeSession();
}
if (errorList.size() > 0) {
throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
}
logMessage("GenerateMeetingsForCustomerAndSavings ran in " + (new DateTimeService().getCurrentDateTime().getMillis() - taskStartTime));
}
use of org.mifos.framework.components.batchjobs.exceptions.BatchJobException in project head by mifos.
the class LoanArrearsAgingHelper method generateLoanArrearsAging.
private void generateLoanArrearsAging() throws BatchJobException {
StaticHibernateUtil.startTransaction();
try {
Query insert_select = StaticHibernateUtil.getSessionTL().getNamedQuery("generateLoanArrearsAging");
insert_select.setParameter("CURRENT_DATE", new LocalDate().toString());
insert_select.executeUpdate();
StaticHibernateUtil.commitTransaction();
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new BatchJobException(e);
}
}
use of org.mifos.framework.components.batchjobs.exceptions.BatchJobException in project head by mifos.
the class LoanArrearsAgingHelper method deleteAllLoanArrearsAging.
private void deleteAllLoanArrearsAging() throws BatchJobException {
StaticHibernateUtil.startTransaction();
try {
Query delete = StaticHibernateUtil.getSessionTL().getNamedQuery("deleteAllLoanArrearsAging");
delete.executeUpdate();
StaticHibernateUtil.commitTransaction();
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new BatchJobException(e);
}
}
use of org.mifos.framework.components.batchjobs.exceptions.BatchJobException in project head by mifos.
the class ApplyPenaltyToLoanAccountsHelper method execute.
@Override
public void execute(final long timeInMillis) throws BatchJobException {
setCurrentDates(timeInMillis);
List<String> errorList = new ArrayList<String>();
List<LoanBO> loanAccounts;
try {
loanAccounts = getLoanAccounts();
} catch (Exception e) {
throw new BatchJobException(e);
}
if (loanAccounts != null && !loanAccounts.isEmpty()) {
Integer loanAccountId = null;
try {
for (LoanBO loanAccount : loanAccounts) {
loanAccountId = loanAccount.getAccountId();
List<AccountPenaltiesEntity> penaltyEntities = new ArrayList<AccountPenaltiesEntity>(loanAccount.getAccountPenalties());
for (AccountPenaltiesEntity penaltyEntity : penaltyEntities) {
List<LoanScheduleEntity> lateInstallments = loanAccount.getDetailsOfLateInstallmentsPeriod(new LocalDate(penaltyEntity.getCreatedDate()), currentLocalDate);
for (LoanScheduleEntity entity : lateInstallments) {
//check grace period for installment period type
if (penaltyEntity.getPenalty().getPeriodType().getPenaltyPeriod() == PenaltyPeriod.INSTALLMENTS && penaltyEntity.hasPeriodType()) {
if (lateInstallments.get(0).getInstallmentId().equals(entity.getInstallmentId()) && checkGracePeriodTypeInstallments(lateInstallments, penaltyEntity.getPenalty().getPeriodDuration())) {
continue;
}
} else //check grace period for daily period type
if (penaltyEntity.getPenalty().getPeriodType().getPenaltyPeriod() == PenaltyPeriod.DAYS && penaltyEntity.hasPeriodType()) {
if (checkGracePeriodTypeDays(entity, penaltyEntity.getPenalty().getPeriodDuration())) {
continue;
}
}
LoanPenaltyScheduleEntity penaltySchedule = entity.getPenaltyScheduleEntity(penaltyEntity.getPenalty().getPenaltyId());
if (checkPeriod(penaltyEntity, new LocalDate(entity.getActionDate().getTime())) || (penaltySchedule != null && penaltySchedule.isOn(currentLocalDate))) {
continue;
}
if (penaltyEntity.isAmountPenalty()) {
addAmountPenalty(penaltyEntity, loanAccount, entity);
} else {
addRatePenalty(penaltyEntity, loanAccount, entity);
}
}
}
}
} catch (Exception e) {
if (loanAccountId != null) {
getLogger().error(String.format("ApplyPenaltyToLoanAccountsTask execute failed with exception %s: %s at loan account %s", e.getClass().getName(), e.getMessage(), loanAccountId.toString()), e);
errorList.add(loanAccountId.toString());
}
StaticHibernateUtil.rollbackTransaction();
} finally {
StaticHibernateUtil.closeSession();
}
}
if (!errorList.isEmpty()) {
throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
}
}
Aggregations