package com.eactive.eai.rms.onl.server.repository;

import org.apache.commons.collections.map.MultiKeyMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.eactive.eai.rms.onl.vo.TransactionTrackingVo;

@Service("transactionRepositoryService")
public class TransactionRepositoryService {

	@Autowired
	@Qualifier("transactionRepository")
	private TransactionRepository transactionRepository;

	public TransactionTrackingVo getTrackingVo(TransactionTrackingVo vo) {

		if (vo != null && vo.getHostName() != null && vo.getInstanceName() != null) {
			return getTrackingVo(vo.getHostName(), vo.getInstanceName());
		} else {
			return null;
		}
	}

	public TransactionTrackingVo getTrackingVo(String hostName, String instance) {
		return (TransactionTrackingVo) transactionRepository.getRepository().get(hostName, instance);
	}

	public void clearRepository() {
		transactionRepository.clearRepository();
	}

	public void clearRepository(String hostName, String instance) {
		transactionRepository.clearRepository(hostName, instance);
	}

	public void checkRepository() {
		transactionRepository.checkRepository();
	}

	public void setTrackingVo(TransactionTrackingVo vo) {
		if (vo != null && vo.getHostName() != null && vo.getInstanceName() != null) {
			transactionRepository.getRepository().put(vo.getHostName(), vo.getInstanceName(), vo);
		}
	}

	public MultiKeyMap getAllTrackingVo() {
		return transactionRepository.getRepository();
	}

	public void backupRepository() {
		transactionRepository.writeTransactionRepository(transactionRepository);
	}
}
