package com.jasamedika.medifirst2000.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jasamedika.medifirst2000.vo.InstitusiPendidikanVO;
import com.jasamedika.medifirst2000.vo.JurusanPeminatanVO;
import com.jasamedika.medifirst2000.vo.FakultasVO;

	import com.jasamedika.medifirst2000.entities.InstitusiPendidikan;
import com.jasamedika.medifirst2000.entities.JurusanPeminatan;
import com.jasamedika.medifirst2000.entities.Fakultas;


import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.PernelitianEksternalService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.entities.PernelitianEksternal;
import com.jasamedika.medifirst2000.vo.PernelitianEksternalVO;
import com.jasamedika.medifirst2000.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.dao.PernelitianEksternalDao;

/**
 * Implement class for PernelitianEksternalService
 * 
 * @author Generator
 * @param <T>
 */
@Service("pernelitianEksternalService")
public class PernelitianEksternalServiceImpl extends BaseVoServiceImpl implements PernelitianEksternalService 
{	
	@Autowired
	private BaseConverterImpl<PernelitianEksternalVO,PernelitianEksternal>pernelitianEksternalConverter;
	@Autowired
private BaseConverterImpl<InstitusiPendidikanVO,InstitusiPendidikan>institusiPendidikanConverter;

@Autowired
private BaseConverterImpl<JurusanPeminatanVO,JurusanPeminatan>jurusanPeminatanConverter;

@Autowired
private BaseConverterImpl<FakultasVO,Fakultas>fakultasConverter;


	@Autowired
	private PernelitianEksternalDao pernelitianEksternalDao;

	
	@Override
	public Map<String, Object> savePernelitianEksternal(PernelitianEksternalVO vo) {
		Map<String, Object> result = new HashMap<String, Object>();
		PernelitianEksternal model = new PernelitianEksternal();
		model = pernelitianEksternalConverter.transferVOToModel(vo,model);
		
		if (CommonUtil.isNotNullOrEmpty(vo.getInstitusiPendidikan()))
		{
				model.setInstitusiPendidikan(institusiPendidikanConverter.transferVOToModel(vo.getInstitusiPendidikan(), new InstitusiPendidikan()));
		}
		if (CommonUtil.isNotNullOrEmpty(vo.getJurusanPeminatan()))
		{
				model.setJurusanPeminatan(jurusanPeminatanConverter.transferVOToModel(vo.getJurusanPeminatan(), new JurusanPeminatan()));
		}
		if (CommonUtil.isNotNullOrEmpty(vo.getFakultas()))
		{
				model.setFakultas(fakultasConverter.transferVOToModel(vo.getFakultas(), new Fakultas()));
		}

		PernelitianEksternal resultDomain = pernelitianEksternalDao.save(model);
		if (CommonUtil.isNotNullOrEmpty(resultDomain)) {
			result.put("noRec", resultDomain.getNoRec());
		}

		return result;
	}
}