package com.ejie.m62fb.service.registroVPP;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

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

import com.ejie.m62fb.dao.registroVPP.DocumentosDao;
import com.ejie.m62fb.model.documento.Documento;
import com.ejie.m62fb.model.documento.DocumentoRegVPP;
import com.ejie.x38.dto.JQGridRequestDto;
import com.ejie.x38.dto.JQGridResponseDto;

/**
 * DocumentosServiceImpl generated by UDA, 04-sep-2015 12:03:48.
XXXX
 */

@Service(value = "documentosService")
public class DocumentosServiceImpl implements DocumentosService {

	@Autowired
	private DocumentosDao documentosDao;
	
	@Override
	@Transactional(rollbackFor = Throwable.class)
	public DocumentoRegVPP add(DocumentoRegVPP documentoRegVPP) {
		this.documentosDao.add(documentoRegVPP);
		this.documentosDao.addSource(documentoRegVPP.getDocumento());
		this.documentosDao.addRelacionDocElem(documentoRegVPP);
		return documentoRegVPP;
	}
	@Override
	@Transactional(rollbackFor = Throwable.class)
@PreAuthorize("hasPermission('DOCUMENTOS_SERVICE','SecureService','delete')")
	public void remove(DocumentoRegVPP documentoRegVPP){
		this.documentosDao.remove(documentoRegVPP);
	}
	@Override
	@PreAuthorize("hasPermission('DOCUMENTOS_SERVICE','SecureService','read')")
	public Documento find(Documento documento) throws SQLException, IOException {
		return (Documento) this.documentosDao.find(documento);
	}
	

	@Override	
@PreAuthorize("hasPermission('DOCUMENTOS_SERVICE','SecureService','read')")
	public JQGridResponseDto< DocumentoRegVPP> filter(DocumentoRegVPP filterDocumento, JQGridRequestDto jqGridRequestDto,Boolean startsWith){
		List<DocumentoRegVPP> listaDocumento =  this.documentosDao.findAllLike(filterDocumento, jqGridRequestDto,startsWith);
		Long recordNum =  this.documentosDao.findAllLikeCount(filterDocumento != null ? filterDocumento: new DocumentoRegVPP (),startsWith);
		return new JQGridResponseDto<DocumentoRegVPP>(jqGridRequestDto, recordNum, listaDocumento);   
	}
    
	
}

