package com.rjconsultores.ventaboletos.web.gui.controladores.job;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.context.ApplicationContext;

import com.rjconsultores.ventaboletos.service.SapService;
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;

public class IntegracaoSapJob implements Job {

    private static Logger log = LogManager.getLogger(IntegracaoSapJob.class);    
    private SapService sapService;

    public SapService getSapService() {
        return sapService;
    }

    @Override
    public void execute(JobExecutionContext jec) throws JobExecutionException {
        log.info("Inicio do job de integração de boletos com o SAP.");

        ApplicationContext appContext = AppContext.getApplicationContext();
        SapService iss = (SapService) appContext.getBean("sapService");
        try {
			iss.integracaoSapAutomatica();
		} catch (Exception e) {
			log.error(e);
		}

        log.info("Fim do job de integração de boletos com o SAP.");
    }
}
