package com.ejie.ab39a.service;
import com.ejie.ab39a.dao.TipoOrganizacionDao;
import com.ejie.x38.dto.JQGridRequestDto;
import com.ejie.x38.dto.JQGridResponseDto;
import com.ejie.x38.dto.TableRowDto;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ejie.ab39a.model.TipoOrganizacion;

/**
 * TipoOrganizacion.
 *  
 */
@Service(value = "tipoOrganizacionService")
public class TipoOrganizacionServiceImpl implements TipoOrganizacionService {

	@Autowired
	private TipoOrganizacionDao tipoOrganizacionDao;

	/**
	 * Inserts a single row in the TipoOrganizacion table.
	 *
	 * @param tipoOrganizacion TipoOrganizacion
	 * @return TipoOrganizacion
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public TipoOrganizacion add(TipoOrganizacion tipoOrganizacion) {
		return this.tipoOrganizacionDao.add(tipoOrganizacion);
	}

	/**
	 * Updates a single row in the TipoOrganizacion table.
	 *
	 * @param tipoOrganizacion TipoOrganizacion
	 * @return TipoOrganizacion
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public TipoOrganizacion update(TipoOrganizacion tipoOrganizacion) {
		return this.tipoOrganizacionDao.update(tipoOrganizacion);
	 }

	/**
	 * Finds a single row in the TipoOrganizacion table.
	 *
	 * @param tipoOrganizacion TipoOrganizacion
	 * @return TipoOrganizacion
	 */
	@Override
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
	public TipoOrganizacion find(TipoOrganizacion tipoOrganizacion) {
		return this.tipoOrganizacionDao.find(tipoOrganizacion);
	}
	
	/**
	 * Deletes a single row in the TipoOrganizacion table.
	 *
	 * @param tipoOrganizacion TipoOrganizacion
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public void remove(TipoOrganizacion tipoOrganizacion) {
		this.tipoOrganizacionDao.remove(tipoOrganizacion);
	}

	/**
	 * Finds a list of rows in the TipoOrganizacion table.
	 *
	 * @param tipoOrganizacion TipoOrganizacion
	 * @param jqGridRequestDto JQGridRequestDto
	 * @return List<TipoOrganizacion>
	 */
	@Override
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
	public List<TipoOrganizacion> findAll(TipoOrganizacion tipoOrganizacion, JQGridRequestDto jqGridRequestDto){
		return this.tipoOrganizacionDao.findAll(tipoOrganizacion, jqGridRequestDto);
	}
    
	/**
	 * Finds rows in the TipoOrganizacion table using like.
	 *
	 * @param tipoOrganizacion TipoOrganizacion
	 * @param jqGridRequestDto JQGridRequestDto
     * @param startsWith Boolean	 
	 * @return List<TipoOrganizacion>
	 */
	@Override
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED) 
	public List<TipoOrganizacion> findAllLike(TipoOrganizacion tipoOrganizacion, JQGridRequestDto jqGridRequestDto, Boolean startsWith){
		return this.tipoOrganizacionDao.findAllLike(tipoOrganizacion, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */
	 
	/**
	 * Removes rows from the TipoOrganizacion table.
	 *
	 * @param filterTipoOrganizacion TipoOrganizacion
	 * @param jqGridRequestDto JQGridRequestDto
	 * @param startsWith Boolean
	 */	
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public void removeMultiple(TipoOrganizacion filterTipoOrganizacion, JQGridRequestDto jqGridRequestDto,  Boolean startsWith){
		this.tipoOrganizacionDao.removeMultiple(filterTipoOrganizacion, jqGridRequestDto, startsWith);
	}
        
	/**
	 * Filter method in the TipoOrganizacion table.
	 *
	 * @param filterTipoOrganizacion TipoOrganizacion
	 * @param jqGridRequestDto JQGridRequestDto
	 * @param startsWith Boolean
	 * @return JQGridResponseDto<TipoOrganizacion>
	 */
	@Override	
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
	public JQGridResponseDto< TipoOrganizacion> filter(TipoOrganizacion filterTipoOrganizacion, JQGridRequestDto jqGridRequestDto,  Boolean startsWith){
		List<TipoOrganizacion> listaTipoOrganizacion =  this.tipoOrganizacionDao.findAllLike(filterTipoOrganizacion, jqGridRequestDto, false);
		Long recordNum =  this.tipoOrganizacionDao.findAllLikeCount(filterTipoOrganizacion != null ? filterTipoOrganizacion: new TipoOrganizacion (),false);
		if (jqGridRequestDto.getMultiselection().getSelectedIds()!=null){
			List< TableRowDto< TipoOrganizacion>> reorderSelection = this.tipoOrganizacionDao.reorderSelection(filterTipoOrganizacion, jqGridRequestDto, startsWith);
			return new JQGridResponseDto<TipoOrganizacion>(jqGridRequestDto, recordNum, listaTipoOrganizacion, reorderSelection);
		}
		return new JQGridResponseDto<TipoOrganizacion>(jqGridRequestDto, recordNum, listaTipoOrganizacion);   
	}
    
    /**
	 * Reorder the selection made in TipoOrganizacion table.
	 *
	 * @param filterTipoOrganizacion TipoOrganizacion
	 * @param jqGridRequestDto JQGridRequestDto
	 * @param startsWith Boolean
	 * @return Object
	 */	
	@Override
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
    public Object reorderSelection(TipoOrganizacion filterTipoOrganizacion, JQGridRequestDto jqGridRequestDto, Boolean startsWith){
		return this.tipoOrganizacionDao.reorderSelection(filterTipoOrganizacion, jqGridRequestDto, startsWith);
	}
    	
}
