package com.eactive.eai.rms.ext.meta.epb;

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

public class EpbMetaSyncJob implements Job {

	private static final Logger logger = Logger.getLogger(EpbMetaSyncJob.class);

	public void execute(JobExecutionContext context) throws JobExecutionException {

		ApplicationContext appContext = null;
		
		try {
			appContext = (ApplicationContext) context.getScheduler().getContext().get("applicationContext");
		} catch (SchedulerException e1) {
			logger.error(e1);
		}
		
		if (appContext == null) {
			logger.info("[EpbMetaSyncJob.metaSync ]appContext is null");
		}
		
		if (appContext.getBean("epbMetaSyncService") == null) {
			logger.info("[EpbMetaSyncJob.metaSync ] epbMetaSyncService is null");
		}

		EpbMetaService service = (EpbMetaService) appContext.getBean("epbMetaSyncService");

		logger.info("[EpbMetaSyncJob.metaSync START]----------");

		try {

			service.sync();

		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		} finally {
			logger.info("[EpbMetaSyncJob.metaSync END]----------");
		}

	}
}
