/*
* Copyright 2021 E.J.I.E., S.A.
*
* Licencia con arreglo a la EUPL, Versión 1.1 exclusivamente (la «Licencia»);
* Solo podrá usarse esta obra si se respeta la Licencia.
* Puede obtenerse una copia de la Licencia en
*
* http://ec.europa.eu/idabc/eupl.html
*
* Salvo cuando lo exija la legislación aplicable o se acuerde por escrito,
* el programa distribuido con arreglo a la Licencia se distribuye «TAL CUAL»,
* SIN GARANT�?AS NI CONDICIONES DE NINGÚN TIPO, ni expresas ni implícitas.
* Véase la Licencia en el idioma concreto que rige los permisos y limitaciones
* que establece la Licencia.
*/
package com.ejie.ad74a.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.dao.support.DataAccessUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ejie.ad74a.dao.comun.UtilDAO;
import com.ejie.ad74a.model.BandejaPapel0;
import com.ejie.ad74a.model.DocumentoPapel0;
import com.ejie.ad74a.model.MaestroTiposDoc;
import com.ejie.ad74a.util.UtilSQL;
import com.ejie.x38.dao.RowNumResultSetExtractor;
import com.ejie.x38.dto.TableManager;
import com.ejie.x38.dto.TableRequestDto;
import com.ejie.x38.dto.TableRowDto;

/**
 * DocumentoPapel0DaoImpl generated by UDA, 19-abr-2023 10:08:13.
 * 
 * @author UDA
 */

@Repository
@Transactional
public class DocumentoPapel0DaoImpl implements DocumentoPapel0Dao {

	/**
	 * StringBuilder initilization value
	 */
	public static final int STRING_BUILDER_INIT = 4096;

	protected static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDDOCPAPEL013", "OIDDOCUMENTO13",
			"NOMBREDOC13", "EXTENSION13", "BANDEJAPAPEL0IDENTRADA12", "BANDEJAPAPEL0FLECTURA12", "BANDEJAPAPEL0IDJMS12",
			"BANDEJAPAPEL0NUMREGISTRO12", "BANDEJAPAPEL0FREGISTRO12", "BANDEJAPAPEL0QRCODE12", "BANDEJAPAPEL0MENSAJE12",
			"BANDEJAPAPEL0ESTADO12", "BANDEJAPAPEL0BLOQUEO12", "BANDEJAPAPEL0TIPO12", "BANDEJAPAPEL0REMITENTE12",
			"BANDEJAPAPEL0NUMREGORIGINAL12", "BANDEJAPAPEL0FREGORIGINAL12", "BANDEJAPAPEL0USURESPONSABLE12",
			"BANDEJAPAPEL0NUMEXPEDIENTE12", "BANDEJAPAPEL0PROCEDUREID12", "BANDEJAPAPEL0RESUMEN12",
			"BANDEJAPAPEL0URGENCIA12", "BANDEJAPAPEL0MOTIVOOCULTAR12", "DESCES36", "DESCEU36" };

	private JdbcTemplate jdbcTemplate;

	public static final String SEQUENCE_DOC_BANDEJA_PAPEL0 = "SEQ_DOCUMENTO_PAPEL0";

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<DocumentoPapel0> rwMap = new RowMapper<DocumentoPapel0>() {
		public DocumentoPapel0 mapRow(ResultSet resultSet, int rowNum) throws SQLException {

			BandejaPapel0 bandejaPapel0 = new BandejaPapel0(UtilSQL.getLong(resultSet, "BandejaPapel0IDENTRADA12"),
					resultSet.getString("BandejaPapel0PROCEDUREID12"), resultSet.getDate("BandejaPapel0FLECTURA12"),
					resultSet.getString("BandejaPapel0IDJMS12"), resultSet.getString("BandejaPapel0NUMREGISTRO12"),
					resultSet.getDate("BandejaPapel0FREGISTRO12"), resultSet.getString("BandejaPapel0QRCODE12"),
					resultSet.getClob("BandejaPapel0MENSAJE12"), resultSet.getString("BandejaPapel0ESTADO12"),
					UtilSQL.getInt(resultSet, "BandejaPapel0BLOQUEO12"), resultSet.getString("BandejaPapel0TIPO12"),
					resultSet.getString("BandejaPapel0TIPOPROCESO12"), resultSet.getString("BandejaPapel0REMITENTE12"),
					resultSet.getString("BandejaPapel0NUMREGORIGINAL12"),
					resultSet.getDate("BandejaPapel0FREGORIGINAL12"),
					resultSet.getString("BandejaPapel0USURESPONSABLE12"),
					resultSet.getString("BandejaPapel0NUMEXPEDIENTE12"), resultSet.getString("BandejaPapel0RESUMEN12"),
					UtilSQL.getInt(resultSet, "BandejaPapel0URGENCIA12"), resultSet.getDate("BandejaPapel0FALTA12"),
					resultSet.getString("BandejaPapel0USUALTA12"), resultSet.getDate("BandejaPapel0FMODIF12"),
					resultSet.getString("BandejaPapel0USUMODIF12"), resultSet.getString("BandejaPapel0OBSERVACIONES12"),
					resultSet.getString("BandejaPapel0MOTIVOOCULTAR12"));

			DocumentoPapel0 documentoPapel0 = new DocumentoPapel0(UtilSQL.getLong(resultSet, "IDDOCPAPEL013"),
					resultSet.getString("OIDDOCUMENTO13"), resultSet.getString("NOMBREDOC13"),
					resultSet.getString("EXTENSION13"), UtilSQL.getLong(resultSet, "IDTIPODOC13"),
					resultSet.getString("USUALTA13"), resultSet.getDate("FALTA13"), resultSet.getString("USUMODIF13"),
					resultSet.getDate("FMODIF13"), UtilSQL.getLong(resultSet, "IDEXPEDIENTE13"), bandejaPapel0);

			MaestroTiposDoc tipoDocumento = new MaestroTiposDoc();

			if (UtilDAO.hasColumn(resultSet, "DESCES36") && null != resultSet.getObject("DESCES36")) {
				tipoDocumento.setDescEs36(resultSet.getString("DESCES36"));
			}
			if (UtilDAO.hasColumn(resultSet, "DESCEU36") && null != resultSet.getObject("DESCEU36")) {
				tipoDocumento.setDescEu36(resultSet.getString("DESCEU36"));
			}
			if (UtilDAO.hasColumn(resultSet, "ORIGEN36") && null != resultSet.getObject("ORIGEN36")) {
				tipoDocumento.setOrigen36(resultSet.getString("ORIGEN36"));
			}
			if (UtilDAO.hasColumn(resultSet, "ROLEID36") && null != resultSet.getObject("ROLEID36")) {
				tipoDocumento.setRoleid36(resultSet.getString("ROLEID36"));
			}
			documentoPapel0.setTipoDocumento(tipoDocumento);

			return documentoPapel0;
		}
	};

	private RowMapper<DocumentoPapel0> rwMapPK = new RowMapper<DocumentoPapel0>() {
		public DocumentoPapel0 mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new DocumentoPapel0(UtilSQL.getLong(resultSet, "IDDOCPAPEL013"));
		}
	};

	/**
	 * Method use to set the datasource.
	 *
	 * @param dataSource DataSource
	 *
	 * @return
	 */
	@Resource
	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}

	/*
	 * OPERACIONES CRUD
	 */

	/**
	 * Inserts a single row in the DocumentoPapel0 table.
	 *
	 * @param documentopapel0 DocumentoPapel0
	 *
	 * @return DocumentoPapel0
	 */
	public DocumentoPapel0 add(DocumentoPapel0 documentopapel0) {

		GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();

		String query = "INSERT INTO DOCUMENTO_PAPEL0 (ID_DOC_PAPEL0_13, ID_ENTRADA_13, OID_DOCUMENTO_13, NOMBRE_DOC_13, EXTENSION_13, ID_TIPO_DOC_13, ID_EXPEDIENTE_13, USU_ALTA_13, F_ALTA_13, USU_MODIF_13, F_MODIF_13) "
				+ "VALUES (" + SEQUENCE_DOC_BANDEJA_PAPEL0
				+ ".NEXTVAL,:idEntrada,:oid,:nombre, :extension, :idTipoDoc,:idExpediente,:usuAlta,sysdate,:usuModif,:fModif)";

		MapSqlParameterSource parameters = new MapSqlParameterSource()
				.addValue("idEntrada", documentopapel0.getBandejaPapel0().getIdEntrada12())
				.addValue("oid", documentopapel0.getOidDocumento13())
				.addValue("nombre", documentopapel0.getNombreDoc13())
				.addValue("extension", documentopapel0.getExtension13())
				.addValue("idTipoDoc", documentopapel0.getIdTipoDoc13())
				.addValue("idExpediente", documentopapel0.getIdExpediente13())
				.addValue("usuAlta", documentopapel0.getUsuAlta13())
				.addValue("usuModif", documentopapel0.getUsuModif13())
				.addValue("fModif", documentopapel0.getfModif13());

		NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
		namedParameterJdbcTemplate.update(query, parameters, generatedKeyHolder, new String[] { "ID_DOC_PAPEL0_13" });
		documentopapel0.setIdDocPapel013(generatedKeyHolder.getKey().longValue());

		return documentopapel0;
	}

	/**
	 * Updates a single row in the DocumentoPapel0 table.
	 *
	 * @param documentopapel0 DocumentoPapel0
	 *
	 * @return DocumentoPapel0
	 */
	public DocumentoPapel0 update(DocumentoPapel0 documentopapel0) {
		String query = "UPDATE DOCUMENTO_PAPEL0 SET ID_ENTRADA_13=?, OID_DOCUMENTO_13=?, NOMBRE_DOC_13 = ?, EXTENSION_13 = ? ,ID_TIPO_DOC_13=?, ID_EXPEDIENTE_13=?, USU_MODIF_13=?, F_MODIF_13 = SYSDATE WHERE ID_DOC_PAPEL0_13=?";
		Object getBandejaPapel0IdEntrada12Aux = null;
		if (documentopapel0.getBandejaPapel0() != null && documentopapel0.getBandejaPapel0().getIdEntrada12() != null) {
			getBandejaPapel0IdEntrada12Aux = documentopapel0.getBandejaPapel0().getIdEntrada12();
		}
		this.jdbcTemplate.update(query, documentopapel0.getIdDocPapel013(), getBandejaPapel0IdEntrada12Aux,
				documentopapel0.getOidDocumento13(), documentopapel0.getNombreDoc13(), documentopapel0.getExtension13(),
				documentopapel0.getIdTipoDoc13(), documentopapel0.getIdExpediente13(), documentopapel0.getUsuModif13());
		return documentopapel0;
	}

	/**
	 * Updates the roleId of a document
	 * 
	 * @param documentosEntrada
	 * @return DocumentosEntrada
	 */
	public DocumentoPapel0 updateRoleDocument(DocumentoPapel0 documentoPapel0) {
		String query = "UPDATE DOCUMENTO_PAPEL0 SET ID_TIPO_DOC_13=?, F_MODIF_13=SYSDATE, USU_MODIF_13=? WHERE OID_DOCUMENTO_13=?";

		this.jdbcTemplate.update(query, documentoPapel0.getIdTipoDoc13(), documentoPapel0.getUsuModif13(),
				documentoPapel0.getOidDocumento13());

		return documentoPapel0;
	}

	public DocumentoPapel0 updateExtension(DocumentoPapel0 documentoPapel0) {
		String query = "UPDATE DOCUMENTO_PAPEL0 SET EXTENSION_13=?, F_MODIF_13=SYSDATE, USU_MODIF_13=? WHERE OID_DOCUMENTO_13=?";

		this.jdbcTemplate.update(query, documentoPapel0.getExtension13(), documentoPapel0.getUsuModif13(),
				documentoPapel0.getOidDocumento13());

		return documentoPapel0;
	}

	public DocumentoPapel0 updateNombre(DocumentoPapel0 documentoPapel0) {
		String query = "UPDATE DOCUMENTO_PAPEL0 SET NOMBRE_DOC_13=?, F_MODIF_13=SYSDATE, USU_MODIF_13=? WHERE OID_DOCUMENTO_13=?";

		this.jdbcTemplate.update(query, documentoPapel0.getNombreDoc13(), documentoPapel0.getUsuModif13(),
				documentoPapel0.getOidDocumento13());

		return documentoPapel0;
	}

	/**
	 * Updates the expediente of a document
	 * 
	 * @param documentosEntrada
	 * @return DocumentosEntrada
	 */
	public DocumentoPapel0 updateExpediente(DocumentoPapel0 documentoPapel0) {
		String query = "UPDATE DOCUMENTO_PAPEL0 SET ID_EXPEDIENTE_13=?, F_MODIF_13=SYSDATE, USU_MODIF_13=? WHERE OID_DOCUMENTO_13=?";

		this.jdbcTemplate.update(query, documentoPapel0.getIdExpediente13(), documentoPapel0.getUsuModif13(),
				documentoPapel0.getOidDocumento13());

		return documentoPapel0;
	}

	/**
	 * Finds a single row in the DocumentoPapel0 table.
	 *
	 * @param documentopapel0 DocumentoPapel0
	 *
	 * @return DocumentoPapel0
	 */
	@Transactional(readOnly = true)
	public DocumentoPapel0 find(DocumentoPapel0 documentopapel0) {
		String query = "SELECT t1.ID_DOC_PAPEL0_13 IDDOCPAPEL013, t1.OID_DOCUMENTO_13 OIDDOCUMENTO13, t1.NOMBRE_DOC_13 NOMBREDOC13, t1.EXTENSION_13 EXTENSION13, t1.ID_TIPO_DOC_13 IDTIPODOC13, t1.USU_ALTA_13 USUALTA13, t1.F_ALTA_13 FALTA13, t1.USU_MODIF_13 USUMODIF13, t1.F_MODIF_13 FMODIF13, t1.ID_EXPEDIENTE_13 IDEXPEDIENTE13, "
				+ " t2.ID_ENTRADA_12 BANDEJAPAPEL0IDENTRADA12, t2.PROCEDUREID_12 BANDEJAPAPEL0PROCEDUREID12, t2.F_LECTURA_12 BANDEJAPAPEL0FLECTURA12, t2.IDJMS_12 BANDEJAPAPEL0IDJMS12, t2.NUM_REGISTRO_12 BANDEJAPAPEL0NUMREGISTRO12, t2.F_REGISTRO_12 BANDEJAPAPEL0FREGISTRO12, t2.QRCODE_12 BANDEJAPAPEL0QRCODE12, t2.MENSAJE_12 BANDEJAPAPEL0MENSAJE12, t2.ESTADO_12 BANDEJAPAPEL0ESTADO12, t2.BLOQUEO_12 BANDEJAPAPEL0BLOQUEO12, t2.TIPO_12 BANDEJAPAPEL0TIPO12,t2.TIPO_PROCESO_12 BANDEJAPAPEL0TIPOPROCESO12,  t2.REMITENTE_12 BANDEJAPAPEL0REMITENTE12, t2.NUM_REG_ORIGINAL_12 BANDEJAPAPEL0NUMREGORIGINAL12, t2.F_REG_ORIGINAL_12 BANDEJAPAPEL0FREGORIGINAL12, t2.USU_RESPONSABLE_12 BANDEJAPAPEL0USURESPONSABLE12, t2.NUM_EXPEDIENTE_12 BANDEJAPAPEL0NUMEXPEDIENTE12, t2.RESUMEN_12 BANDEJAPAPEL0RESUMEN12, t2.URGENCIA_12 BANDEJAURGENCIA12, t2.F_ALTA_12 BANDEJAPAPEL0FALTA12, t2.USU_ALTA_12 BANDEJAPAPEL0USUALTA12, t2.F_MODIF_12 BANDEJAPAPEL0FMODIF12, t2.USU_MODIF_12 BANDEJAPAPEL0USUMODIF12, t2.OBSERVACIONES_12 BandejaPapel0OBSERVACIONES12, t2.MOTIVO_OCULTAR_12 BandejaPapel0MOTIVOOCULTAR12, "
				+ " t3.DESC_ES_36 DESCES36, t3.DESC_EU_36 DESCEU36, t3.ORIGEN_36 ORIGEN36, t3.ROLEID_36 ROLEID36 "
				+ " FROM DOCUMENTO_PAPEL0 t1 , BANDEJA_PAPEL0 t2, MAESTRO_TIPOS_DOC t3  WHERE t1.ID_DOC_PAPEL0_13 = ?   AND t1.ID_ENTRADA_13= t2.ID_ENTRADA_12(+) AND t1.ID_TIPO_DOC_13 = t3.ID_TIPO_DOC_36(+)";

		List<DocumentoPapel0> documentopapel0List = this.jdbcTemplate.query(query, this.rwMap,
				documentopapel0.getIdDocPapel013());
		return DataAccessUtils.uniqueResult(documentopapel0List);
	}

	/**
	 * Removes a single row in the DocumentoPapel0 table.
	 *
	 * @param documentopapel0 DocumentoPapel0
	 */
	public void remove(DocumentoPapel0 documentopapel0) {
		String query = "DELETE FROM DOCUMENTO_PAPEL0 WHERE ID_DOC_PAPEL0_13=?";
		this.jdbcTemplate.update(query, documentopapel0.getIdDocPapel013());
	}

	public List<DocumentoPapel0> getMultiple(DocumentoPapel0 filterDocumentoPapel0, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_DOC_PAPEL0_13 IDDOCPAPEL013, t1.OID_DOCUMENTO_13 OIDDOCUMENTO13, t1.NOMBRE_DOC_13 NOMBREDOC13, t1.EXTENSION_13 EXTENSION13, t1.ID_TIPO_DOC_13 IDTIPODOC13,t1.USU_ALTA_13 USUALTA13, t1.F_ALTA_13 FALTA13, t1.USU_MODIF_13 USUMODIF13, t1.F_MODIF_13 FMODIF13, t1.ID_EXPEDIENTE_13 IDEXPEDIENTE13, ");
		query.append(
				" t2.ID_ENTRADA_12 BANDEJAPAPEL0IDENTRADA12, t2.PROCEDUREID_12 BANDEJAPAPEL0PROCEDUREID12, t2.F_LECTURA_12 BANDEJAPAPEL0FLECTURA12, t2.IDJMS_12 BANDEJAPAPEL0IDJMS12, t2.NUM_REGISTRO_12 BANDEJAPAPEL0NUMREGISTRO12, t2.F_REGISTRO_12 BANDEJAPAPEL0FREGISTRO12, t2.QRCODE_12 BANDEJAPAPEL0QRCODE12, t2.MENSAJE_12 BANDEJAPAPEL0MENSAJE12, t2.ESTADO_12 BANDEJAPAPEL0ESTADO12, t2.BLOQUEO_12 BANDEJAPAPEL0BLOQUEO12, t2.TIPO_12 BANDEJAPAPEL0TIPO12,t2.TIPO_PROCESO_12 BANDEJAPAPEL0TIPOPROCESO12, t2.REMITENTE_12 BANDEJAPAPEL0REMITENTE12, t2.NUM_REG_ORIGINAL_12 BANDEJAPAPEL0NUMREGORIGINAL12, t2.F_REG_ORIGINAL_12 BANDEJAPAPEL0FREGORIGINAL12, t2.USU_RESPONSABLE_12 BANDEJAPAPEL0USURESPONSABLE12, t2.NUM_EXPEDIENTE_12 BANDEJAPAPEL0NUMEXPEDIENTE12, t2.RESUMEN_12 BANDEJAPAPEL0RESUMEN12, t2.URGENCIA_12 BANDEJAURGENCIA12, t2.F_ALTA_12 BANDEJAPAPEL0FALTA12, t2.USU_ALTA_12 BANDEJAPAPEL0USUALTA12, t2.F_MODIF_12 BANDEJAPAPEL0FMODIF12, t2.USU_MODIF_12 BANDEJAPAPEL0USUMODIF12, t2.OBSERVACIONES_12 BandejaPapel0OBSERVACIONES12, t2.MOTIVO_OCULTAR_12 BandejaPapel0MOTIVOOCULTAR12 ");
		// FROM
		query.append(" FROM DOCUMENTO_PAPEL0 t1 , BANDEJA_PAPEL0 t2 ");
		// WHERE clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterDocumentoPapel0, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append(mapaWhere.get("query"));
		query.append(where);

		@SuppressWarnings("unchecked")
		List<Object> params = (List<Object>) mapaWhere.get("params");

		StringBuilder sbMultipleSQL = query.append(TableManager.getSelectMultipleQuery(tableRequestDto,
				DocumentoPapel0.class, params, "id_doc_papel0_13"));

		return this.jdbcTemplate.query(sbMultipleSQL.toString(), this.rwMap, params.toArray());
	}

	/**
	 * Finds a list of rows in the DocumentoPapel0 table.
	 *
	 * @param documentopapel0 DocumentoPapel0
	 * @param tableRequestDto TableRequestDto
	 *
	 * @return List<DocumentoPapel0>
	 */
	@Transactional(readOnly = true)
	public List<DocumentoPapel0> findAll(DocumentoPapel0 documentopapel0, TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_DOC_PAPEL0_13 IDDOCPAPEL013,t1.OID_DOCUMENTO_13 OIDDOCUMENTO13, t1.NOMBRE_DOC_13 NOMBREDOC13, t1.EXTENSION_13 EXTENSION13, t1.ID_TIPO_DOC_13 IDTIPODOC13, t1.USU_ALTA_13 USUALTA13, t1.F_ALTA_13 FALTA13, t1.USU_MODIF_13 USUMODIF13, t1.F_MODIF_13 FMODIF13, t1.ID_EXPEDIENTE_13 IDEXPEDIENTE13, ");
		query.append(
				" t2.ID_ENTRADA_12 BANDEJAPAPEL0IDENTRADA12, t2.PROCEDUREID_12 BANDEJAPAPEL0PROCEDUREID12,t2.F_LECTURA_12 BANDEJAPAPEL0FLECTURA12,t2.IDJMS_12 BANDEJAPAPEL0IDJMS12,t2.NUM_REGISTRO_12 BANDEJAPAPEL0NUMREGISTRO12,t2.F_REGISTRO_12 BANDEJAPAPEL0FREGISTRO12,t2.QRCODE_12 BANDEJAPAPEL0QRCODE12,t2.MENSAJE_12 BANDEJAPAPEL0MENSAJE12,t2.ESTADO_12 BANDEJAPAPEL0ESTADO12,t2.BLOQUEO_12 BANDEJAPAPEL0BLOQUEO12,t2.TIPO_12 BANDEJAPAPEL0TIPO12,t2.TIPO_PROCESO_12 BANDEJAPAPEL0TIPOPROCESO12,t2.REMITENTE_12 BANDEJAPAPEL0REMITENTE12,t2.NUM_REG_ORIGINAL_12 BANDEJAPAPEL0NUMREGORIGINAL12,t2.F_REG_ORIGINAL_12 BANDEJAPAPEL0FREGORIGINAL12,t2.USU_RESPONSABLE_12 BANDEJAPAPEL0USURESPONSABLE12,t2.NUM_EXPEDIENTE_12 BANDEJAPAPEL0NUMEXPEDIENTE12, t2.RESUMEN_12 BANDEJAPAPEL0RESUMEN12, t2.URGENCIA_12 BANDEJAPAPEL0URGENCIA12, t2.F_ALTA_12 BANDEJAPAPEL0FALTA12, t2.USU_ALTA_12 BANDEJAPAPEL0USUALTA12, t2.F_MODIF_12 BANDEJAPAPEL0FMODIF12, t2.USU_MODIF_12 BANDEJAPAPEL0USUMODIF12, t2.OBSERVACIONES_12 BANDEJAPAPEL0OBSERVACIONES12, t2.MOTIVO_OCULTAR_12 BandejaPapel0MOTIVOOCULTAR12 ");
		query.append(" , t3.DESC_ES_36 DESCES36, t3.DESC_EU_36 DESCEU36, t3.ORIGEN_36 ORIGEN36, t3.ROLEID_36 ROLEID36");

		// FROM
		query.append(" FROM DOCUMENTO_PAPEL0 t1 ,BANDEJA_PAPEL0 t2, MAESTRO_TIPOS_DOC t3 ");

		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereMap(documentopapel0);
		StringBuilder where = new StringBuilder(
				" WHERE 1=1 AND t1.ID_ENTRADA_13= t2.ID_ENTRADA_12(+) AND t1.ID_TIPO_DOC_13 = t3.ID_TIPO_DOC_36(+) ");
		where.append(mapaWhere.get("query"));
		query.append(where);

		List<?> params = (List<?>) mapaWhere.get("params");

		if (tableRequestDto != null) {
			query = TableManager.getPaginationQuery(tableRequestDto, query, DocumentoPapel0DaoImpl.ORDER_BY_WHITE_LIST);
		}

		return this.jdbcTemplate.query(query.toString(), this.rwMap, params.toArray());
	}

	/**
	 * Finds rows in the DocumentoPapel0 table using like.
	 *
	 * @param documentopapel0 DocumentoPapel0
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 *
	 * @return List<DocumentoPapel0>
	 */
	@Transactional(readOnly = true)
	public List<DocumentoPapel0> findAllLike(DocumentoPapel0 documentopapel0, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_DOC_PAPEL0_13 IDDOCPAPEL013,t1.OID_DOCUMENTO_13 OIDDOCUMENTO13, t1.NOMBRE_DOC_13 NOMBREDOC13, t1.EXTENSION_13 EXTENSION13, t1.ID_TIPO_DOC_13 IDTIPODOC13, t1.USU_ALTA_13 USUALTA13, t1.F_ALTA_13 FALTA13, t1.USU_MODIF_13 USUMODIF13, t1.F_MODIF_13 FMODIF13, t1.ID_EXPEDIENTE_13 IDEXPEDIENTE13, ");
		query.append(
				" t2.ID_ENTRADA_12 BANDEJAPAPEL0IDENTRADA12, t2.PROCEDUREID_12 BANDEJAPAPEL0PROCEDUREID12,t2.F_LECTURA_12 BANDEJAPAPEL0FLECTURA12,t2.IDJMS_12 BANDEJAPAPEL0IDJMS12,t2.NUM_REGISTRO_12 BANDEJAPAPEL0NUMREGISTRO12,t2.F_REGISTRO_12 BANDEJAPAPEL0FREGISTRO12,t2.QRCODE_12 BANDEJAPAPEL0QRCODE12,t2.MENSAJE_12 BANDEJAPAPEL0MENSAJE12,t2.ESTADO_12 BANDEJAPAPEL0ESTADO12,t2.BLOQUEO_12 BANDEJAPAPEL0BLOQUEO12,t2.TIPO_12 BANDEJAPAPEL0TIPO12,t2.TIPO_PROCESO_12 BANDEJAPAPEL0TIPOPROCESO12,t2.REMITENTE_12 BANDEJAPAPEL0REMITENTE12,t2.NUM_REG_ORIGINAL_12 BANDEJAPAPEL0NUMREGORIGINAL12,t2.F_REG_ORIGINAL_12 BANDEJAPAPEL0FREGORIGINAL12,t2.USU_RESPONSABLE_12 BANDEJAPAPEL0USURESPONSABLE12,t2.NUM_EXPEDIENTE_12 BANDEJAPAPEL0NUMEXPEDIENTE12, t2.RESUMEN_12 BANDEJAPAPEL0RESUMEN12, t2.URGENCIA_12 BANDEJAPAPEL0URGENCIA12, t2.F_ALTA_12 BANDEJAPAPEL0FALTA12, t2.USU_ALTA_12 BANDEJAPAPEL0USUALTA12, t2.F_MODIF_12 BANDEJAPAPEL0FMODIF12, t2.USU_MODIF_12 BANDEJAPAPEL0USUMODIF12, t2.OBSERVACIONES_12 BandejaPapel0OBSERVACIONES12, t2.MOTIVO_OCULTAR_12 BandejaPapel0MOTIVOOCULTAR12 ");
		query.append(" , t3.DESC_ES_36 DESCES36, t3.DESC_EU_36 DESCEU36, t3.ORIGEN_36 ORIGEN36, t3.ROLEID_36 ROLEID36");

		// FROM
		query.append(" FROM DOCUMENTO_PAPEL0 t1 ,BANDEJA_PAPEL0 t2, MAESTRO_TIPOS_DOC t3 ");

		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereMap(documentopapel0);
		StringBuilder where = new StringBuilder(
				" WHERE 1=1 AND t1.ID_ENTRADA_13= t2.ID_ENTRADA_12(+) AND t1.ID_TIPO_DOC_13 = t3.ID_TIPO_DOC_36(+) ");
		where.append(mapaWhere.get("query"));
		query.append(where);

		List<?> params = (List<?>) mapaWhere.get("params");

		if (tableRequestDto != null) {
			query = TableManager.getPaginationQuery(tableRequestDto, query, DocumentoPapel0DaoImpl.ORDER_BY_WHITE_LIST);
		}

		return this.jdbcTemplate.query(query.toString(), this.rwMap, params.toArray());
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Counts rows in the DocumentoPapel0 table.
	 *
	 * @param documentopapel0 DocumentoPapel0
	 *
	 * @return Long
	 */
	@Transactional(readOnly = true)
	public Long findAllCount(DocumentoPapel0 documentopapel0) {
		// SELECT
		StringBuilder query = new StringBuilder("SELECT COUNT(1) FROM DOCUMENTO_PAPEL0 t1 , BANDEJA_PAPEL0 t2 ");

		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereMap(documentopapel0);
		StringBuilder where = new StringBuilder(" WHERE 1=1 AND t1.ID_ENTRADA_13= t2.ID_ENTRADA_12(+) ");
		where.append(mapaWhere.get("query"));
		query.append(where);

		List<?> params = (List<?>) mapaWhere.get("params");

		return this.jdbcTemplate.queryForObject(query.toString(), params.toArray(), Long.class);
	}

	/**
	 * Counts rows in the DocumentoPapel0 table using like.
	 *
	 * @param documentopapel0 DocumentoPapel0
	 * @param startsWith      Boolean
	 *
	 * @return Long
	 */
	@Transactional(readOnly = true)
	public Long findAllLikeCount(DocumentoPapel0 documentopapel0, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder("SELECT COUNT(1) FROM DOCUMENTO_PAPEL0 t1 ,BANDEJA_PAPEL0 t2 ");

		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(documentopapel0, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 AND t1.ID_ENTRADA_13= t2.ID_ENTRADA_12(+) ");
		where.append(mapaWhere.get("query"));
		query.append(where);

		List<?> params = (List<?>) mapaWhere.get("params");

		return this.jdbcTemplate.queryForObject(query.toString(), params.toArray(), Long.class);
	}

	/**
	 * Reorder the data list of DocumentoPapel0 selected for rup_table
	 *
	 * @param documentopapel0 DocumentoPapel0
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 *
	 * @return List<TableRowDto<DocumentoPapel0>>
	 */
	@Override
	public List<TableRowDto<DocumentoPapel0>> reorderSelection(DocumentoPapel0 documentopapel0,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_DOC_PAPEL0_13 IDDOCPAPEL013,t1.OID_DOCUMENTO_13 OIDDOCUMENTO13, t1.NOMBRE_DOC_13 NOMBREDOC13, t1.EXTENSION_13 EXTENSION13, t1.ID_TIPO_DOC_13 IDTIPODOC13, t1.USU_ALTA_13 USUALTA13, t1.F_ALTA_13 FALTA13, t1.USU_MODIF_13 USUMODIF13, t1.F_MODIF_13 FMODIF13, t1.ID_EXPEDIENTE_13 IDEXPEDIENTE13, ");
		query.append(
				" t2.ID_ENTRADA_12 BANDEJAPAPEL0IDENTRADA12, t2.PROCEDUREID_12 BANDEJAPAPEL0PROCEDUREID12,t2.F_LECTURA_12 BANDEJAPAPEL0FLECTURA12,t2.IDJMS_12 BANDEJAPAPEL0IDJMS12,t2.NUM_REGISTRO_12 BANDEJAPAPEL0NUMREGISTRO12,t2.F_REGISTRO_12 BANDEJAPAPEL0FREGISTRO12,t2.QRCODE_12 BANDEJAPAPEL0QRCODE12,t2.MENSAJE_12 BANDEJAPAPEL0MENSAJE12,t2.ESTADO_12 BANDEJAPAPEL0ESTADO12,t2.BLOQUEO_12 BANDEJAPAPEL0BLOQUEO12,t2.TIPO_12 BANDEJAPAPEL0TIPO12,t2.REMITENTE_12 BANDEJAPAPEL0REMITENTE12,t2.NUM_REG_ORIGINAL_12 BANDEJAPAPEL0NUMREGORIGINAL12,t2.F_REG_ORIGINAL_12 BANDEJAPAPEL0FREGORIGINAL12,t2.USU_RESPONSABLE_12 BANDEJAPAPEL0USURESPONSABLE12,t2.NUM_EXPEDIENTE_12 BANDEJAPAPEL0NUMEXPEDIENTE12, t2.RESUMEN_12 BANDEJAPAPEL0RESUMEN12, t2.URGENCIA_12 BANDEJAURGENCIA12, t2.F_ALTA_12 BANDEJAPAPEL0FALTA12, t2.USU_ALTA_12 BANDEJAPAPEL0USUALTA12, t2.F_MODIF_12 BANDEJAPAPEL0FMODIF12, t2.USU_MODIF_12 BANDEJAPAPEL0USUMODIF12, t2.OBSERVACIONES_12 BandejaPapel0OBSERVACIONES12 ");

		// FROM
		query.append("FROM DOCUMENTO_PAPEL0 t1 ,BANDEJA_PAPEL0 t2 ");
		// FILTRADO
		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(documentopapel0, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 AND t1.ID_ENTRADA_13= t2.ID_ENTRADA_12(+) ");
		where.append(mapaWhere.get("query"));
		query.append(where);

		// Parámetros de filtrado
		@SuppressWarnings("unchecked")
		List<Object> filterParamList = (List<Object>) mapaWhere.get("params");

		// SQL para la reordenación
		StringBuilder sbReorderSelectionSQL = TableManager.getReorderQuery(query, tableRequestDto,
				DocumentoPapel0.class, filterParamList, "iddocpapel013");

		return this.jdbcTemplate.query(sbReorderSelectionSQL.toString(),
				new RowNumResultSetExtractor<DocumentoPapel0>(this.rwMapPK, tableRequestDto),
				filterParamList.toArray());
	}

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams    DocumentoPapel0
	 * @param searchParams    DocumentoPapel0
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 *
	 * @return List<TableRowDto<DocumentoPapel0>>
	 */
	@Override
	public List<TableRowDto<DocumentoPapel0>> search(DocumentoPapel0 filterParams, DocumentoPapel0 searchParams,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_DOC_PAPEL0_13 IDDOCPAPEL013,t1.OID_DOCUMENTO_13 OIDDOCUMENTO13, t1.NOMBRE_DOC_13 NOMBREDOC13, t1.EXTENSION_13 EXTENSION13, t1.ID_TIPO_DOC_13 IDTIPODOC13, t1.USU_ALTA_13 USUALTA13, t1.F_ALTA_13 FALTA13, t1.USU_MODIF_13 USUMODIF13, t1.F_MODIF_13 FMODIF13, t1.ID_EXPEDIENTE_13 IDEXPEDIENTE13, ");
		query.append(
				" 2.ID_ENTRADA_12 BANDEJAPAPEL0IDENTRADA12,t2.F_LECTURA_12 BANDEJAPAPEL0FLECTURA12, t2.PROCEDUREID_12 BANDEJAPAPEL0PROCEDUREID12,t2.IDJMS_12 BANDEJAPAPEL0IDJMS12,t2.NUM_REGISTRO_12 BANDEJAPAPEL0NUMREGISTRO12,t2.F_REGISTRO_12 BANDEJAPAPEL0FREGISTRO12,t2.QRCODE_12 BANDEJAPAPEL0QRCODE12,t2.MENSAJE_12 BANDEJAPAPEL0MENSAJE12,t2.ESTADO_12 BANDEJAPAPEL0ESTADO12,t2.BLOQUEO_12 BANDEJAPAPEL0BLOQUEO12,t2.TIPO_12 BANDEJAPAPEL0TIPO12,t2.REMITENTE_12 BANDEJAPAPEL0REMITENTE12,t2.NUM_REG_ORIGINAL_12 BANDEJAPAPEL0NUMREGORIGINAL12,t2.F_REG_ORIGINAL_12 BANDEJAPAPEL0FREGORIGINAL12,t2.USU_RESPONSABLE_12 BANDEJAPAPEL0USURESPONSABLE12,t2.NUM_EXPEDIENTE_12 BANDEJAPAPEL0NUMEXPEDIENTE12, t2.RESUMEN_12 BANDEJAPAPEL0RESUMEN12, t2.URGENCIA_12 BANDEJAURGENCIA12, t2.F_ALTA_12 BANDEJAPAPEL0FALTA12, t2.USU_ALTA_12 BANDEJAPAPEL0USUALTA12, t2.F_MODIF_12 BANDEJAPAPEL0FMODIF12, t2.USU_MODIF_12 BANDEJAPAPEL0USUMODIF12 ");

		// FROM
		query.append("FROM DOCUMENTO_PAPEL0 t1 ,BANDEJA_PAPEL0 t2 ");
		// TABLAS_ALIAS
		List<String> from_alias = new ArrayList<String>();
		from_alias.add(" t1 ");
		from_alias.add(" t2 ");

		// FILTRADO
		Map<String, ?> mapaWhereFilter = this.getWhereLikeMap(filterParams, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 AND t1.ID_ENTRADA_13= t2.ID_ENTRADA_12(+) ");
		where.append(mapaWhereFilter.get("query"));
		query.append(where);
		// Filter params
		@SuppressWarnings("unchecked")
		List<Object> filterParamList = (List<Object>) mapaWhereFilter.get("params");

		// BUSQUEDA
		Map<String, Object> mapaWhereSearch = this.getWhereLikeMap(searchParams, startsWith);
		String searchSQL = ((StringBuilder) mapaWhereSearch.get("query")).toString();
		// Search params
		@SuppressWarnings("unchecked")
		List<Object> searchParamList = (List<Object>) mapaWhereSearch.get("params");

		// SQL
		StringBuilder sbReorderSelectionSQL = TableManager.getSearchQuery(query, tableRequestDto, DocumentoPapel0.class,
				filterParamList, searchSQL, searchParamList, from_alias, "IDDOCPAPEL013");

		return this.jdbcTemplate.query(sbReorderSelectionSQL.toString(),
				new RowNumResultSetExtractor<DocumentoPapel0>(this.rwMapPK, tableRequestDto),
				filterParamList.toArray());
	}

	/**
	 * Remove multiple method for rup_table
	 *
	 * @param tableRequestDto TableRequestDto
	 */
	@Override
	public void removeMultiple(TableRequestDto tableRequestDto) {
		StringBuilder sbRemoveMultipleSQL = TableManager.getRemoveMultipleQuery(null, tableRequestDto,
				DocumentoPapel0.class, "DOCUMENTO_PAPEL0", "t1", new String[] { "IDDOCPAPEL013" });

		List<String> params = tableRequestDto.getMultiselection().getSelectedIds();

		this.jdbcTemplate.update(sbRemoveMultipleSQL.toString(), params.toArray());
	}

	/*
	 * MÃ‰TODOS PRIVADOS
	 */

	/**
	 * Returns a map with the needed value to create the conditions to filter by the
	 * DocumentoPapel0 entity
	 *
	 * @param documentopapel0 DocumentoPapel0 Bean with the criteria values to
	 *                        filter by.
	 *
	 * @return Map created with two keys key query stores the sql query syntax key
	 *         params stores the parameter values to be used in the condition
	 *         sentence.
	 */
	private Map<String, ?> getWhereMap(DocumentoPapel0 documentopapel0) {
		StringBuilder where = new StringBuilder(DocumentoPapel0DaoImpl.STRING_BUILDER_INIT);
		List<Object> params = new ArrayList<Object>();

		if (documentopapel0 != null && documentopapel0.getIdDocPapel013() != null) {
			where.append(" AND t1.ID_DOC_PAPEL0_13 = ?");
			params.add(documentopapel0.getIdDocPapel013());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getIdEntrada12() != null) {
			where.append(" AND t2.ID_ENTRADA_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getIdEntrada12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getfLectura12() != null) {
			where.append(" AND t2.F_LECTURA_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getfLectura12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getIdjms12() != null) {
			where.append(" AND t2.IDJMS_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getIdjms12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getNumRegistro12() != null) {
			where.append(" AND t2.NUM_REGISTRO_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getNumRegistro12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getfRegistro12() != null) {
			where.append(" AND t2.F_REGISTRO_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getfRegistro12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getQrcode12() != null) {
			where.append(" AND t2.QRCODE_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getQrcode12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getEstado12() != null) {
			where.append(" AND t2.ESTADO_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getEstado12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getBloqueo12() != null) {
			where.append(" AND t2.BLOQUEO_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getBloqueo12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getTipo12() != null) {
			where.append(" AND t2.TIPO_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getTipo12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getRemitente12() != null) {
			where.append(" AND t2.REMITENTE_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getRemitente12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getNumRegOriginal12() != null) {
			where.append(" AND t2.NUM_REG_ORIGINAL_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getNumRegOriginal12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getfRegOriginal12() != null) {
			where.append(" AND t2.F_REG_ORIGINAL_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getfRegOriginal12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getUsuResponsable12() != null) {
			where.append(" AND t2.USU_RESPONSABLE_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getUsuResponsable12());
		}

		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getUrgencia12() != null) {
			where.append(" AND t2.URGENCIA_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getUrgencia12());
		}

		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getNumExpediente12() != null) {
			where.append(" AND t2.NUM_EXPEDIENTE_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getNumExpediente12());
		}
		if (documentopapel0 != null && documentopapel0.getOidDocumento13() != null) {
			where.append(" AND t1.OID_DOCUMENTO_13 = ?");
			params.add(documentopapel0.getOidDocumento13());
		}
		if (documentopapel0 != null && documentopapel0.getNombreDoc13() != null) {
			where.append(" AND t1.NOMBRE_DOC_13 = ?");
			params.add(documentopapel0.getNombreDoc13());
		}
		if (documentopapel0 != null && documentopapel0.getExtension13() != null) {
			where.append(" AND t1.EXTENSION_13 = ?");
			params.add(documentopapel0.getExtension13());
		}
		if (documentopapel0 != null && documentopapel0.getUsuAlta13() != null) {
			where.append(" AND t1.USU_ALTA_13 = ?");
			params.add(documentopapel0.getUsuAlta13());
		}
		if (documentopapel0 != null && documentopapel0.getfAlta13() != null) {
			where.append(" AND t1.F_ALTA_13 = ?");
			params.add(documentopapel0.getfAlta13());
		}
		if (documentopapel0 != null && documentopapel0.getUsuModif13() != null) {
			where.append(" AND t1.USU_MODIF_13 = ?");
			params.add(documentopapel0.getUsuModif13());
		}
		if (documentopapel0 != null && documentopapel0.getfModif13() != null) {
			where.append(" AND t1.F_MODIF_13 = ?");
			params.add(documentopapel0.getfModif13());
		}
		if (documentopapel0 != null && documentopapel0.getIdExpediente13() != null) {
			where.append(" AND t1.ID_EXPEDIENTE_13 = ?");
			params.add(documentopapel0.getIdExpediente13());
		}

		Map<String, Object> mapWhere = new HashMap<String, Object>();
		mapWhere.put("query", where);
		mapWhere.put("params", params);

		return mapWhere;
	}

	/**
	 * Returns a map with the needed value to create the conditions to filter by the
	 * DocumentoPapel0 entity
	 *
	 * @param documentopapel0 DocumentoPapel0 Bean with the criteria values to
	 *                        filter by.
	 * @param startsWith      Boolean
	 *
	 * @return Map created with two keys key query stores the sql query syntax key
	 *         params stores the parameter values to be used in the condition
	 *         sentence.
	 */
	private Map<String, Object> getWhereLikeMap(DocumentoPapel0 documentopapel0, Boolean startsWith) {
		StringBuilder where = new StringBuilder(DocumentoPapel0DaoImpl.STRING_BUILDER_INIT);
		List<Object> params = new ArrayList<Object>();

		if (documentopapel0 != null && documentopapel0.getIdDocPapel013() != null) {
			where.append(" AND t1.ID_DOC_PAPEL0_13 = ?");
			params.add(documentopapel0.getIdDocPapel013());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getIdEntrada12() != null) {
			where.append(" AND t2.ID_ENTRADA_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getIdEntrada12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getfLectura12() != null) {
			where.append(" AND t2.F_LECTURA_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getfLectura12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getIdjms12() != null) {
			where.append(" AND UPPER(t2.IDJMS_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(documentopapel0.getBandejaPapel0().getIdjms12().toUpperCase() + "%");
			} else {
				params.add("%" + documentopapel0.getBandejaPapel0().getIdjms12().toUpperCase() + "%");
			}
			where.append(" AND t2.IDJMS_12 IS NOT NULL");
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getNumRegistro12() != null) {
			where.append(" AND UPPER(t2.NUM_REGISTRO_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(documentopapel0.getBandejaPapel0().getNumRegistro12().toUpperCase() + "%");
			} else {
				params.add("%" + documentopapel0.getBandejaPapel0().getNumRegistro12().toUpperCase() + "%");
			}
			where.append(" AND t2.NUM_REGISTRO_12 IS NOT NULL");
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getfRegistro12() != null) {
			where.append(" AND t2.F_REGISTRO_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getfRegistro12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getQrcode12() != null) {
			where.append(" AND UPPER(t2.QRCODE_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(documentopapel0.getBandejaPapel0().getQrcode12().toUpperCase() + "%");
			} else {
				params.add("%" + documentopapel0.getBandejaPapel0().getQrcode12().toUpperCase() + "%");
			}
			where.append(" AND t2.QRCODE_12 IS NOT NULL");
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getEstado12() != null) {
			where.append(" AND UPPER(t2.ESTADO_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(documentopapel0.getBandejaPapel0().getEstado12().toUpperCase() + "%");
			} else {
				params.add("%" + documentopapel0.getBandejaPapel0().getEstado12().toUpperCase() + "%");
			}
			where.append(" AND t2.ESTADO_12 IS NOT NULL");
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getBloqueo12() != null) {
			where.append(" AND t2.BLOQUEO_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getBloqueo12());
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getTipo12() != null) {
			where.append(" AND UPPER(t2.TIPO_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(documentopapel0.getBandejaPapel0().getTipo12().toUpperCase() + "%");
			} else {
				params.add("%" + documentopapel0.getBandejaPapel0().getTipo12().toUpperCase() + "%");
			}
			where.append(" AND t2.TIPO_12 IS NOT NULL");
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getRemitente12() != null) {
			where.append(" AND UPPER(t2.REMITENTE_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(documentopapel0.getBandejaPapel0().getRemitente12().toUpperCase() + "%");
			} else {
				params.add("%" + documentopapel0.getBandejaPapel0().getRemitente12().toUpperCase() + "%");
			}
			where.append(" AND t2.REMITENTE_12 IS NOT NULL");
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getNumRegOriginal12() != null) {
			where.append(" AND UPPER(t2.NUM_REG_ORIGINAL_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(documentopapel0.getBandejaPapel0().getNumRegOriginal12().toUpperCase() + "%");
			} else {
				params.add("%" + documentopapel0.getBandejaPapel0().getNumRegOriginal12().toUpperCase() + "%");
			}
			where.append(" AND t2.NUM_REG_ORIGINAL_12 IS NOT NULL");
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getfRegOriginal12() != null) {
			where.append(" AND t2.F_REG_ORIGINAL_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getfRegOriginal12());
		}

		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getUrgencia12() != null) {
			where.append(" AND t2.URGENCIA_12 = ?");
			params.add(documentopapel0.getBandejaPapel0().getUrgencia12());
		}

		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getUsuResponsable12() != null) {
			where.append(" AND UPPER(t2.USU_RESPONSABLE_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(documentopapel0.getBandejaPapel0().getUsuResponsable12().toUpperCase() + "%");
			} else {
				params.add("%" + documentopapel0.getBandejaPapel0().getUsuResponsable12().toUpperCase() + "%");
			}
			where.append(" AND t2.USU_RESPONSABLE_12 IS NOT NULL");
		}
		if (documentopapel0 != null && documentopapel0.getBandejaPapel0() != null
				&& documentopapel0.getBandejaPapel0().getNumExpediente12() != null) {
			where.append(" AND UPPER(t2.NUM_EXPEDIENTE_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(documentopapel0.getBandejaPapel0().getNumExpediente12().toUpperCase() + "%");
			} else {
				params.add("%" + documentopapel0.getBandejaPapel0().getNumExpediente12().toUpperCase() + "%");
			}
			where.append(" AND t2.NUM_EXPEDIENTE_12 IS NOT NULL");
		}
		if (documentopapel0 != null && documentopapel0.getOidDocumento13() != null) {
			where.append(" AND UPPER(t1.OID_DOCUMENTO_13) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(documentopapel0.getOidDocumento13().toUpperCase() + "%");
			} else {
				params.add("%" + documentopapel0.getOidDocumento13().toUpperCase() + "%");
			}
			where.append(" AND t1.OID_DOCUMENTO_13 IS NOT NULL");
		}
		if (documentopapel0 != null && documentopapel0.getNombreDoc13() != null) {
			where.append(" AND UPPER(t1.NOMBRE_DOC_13) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(documentopapel0.getNombreDoc13().toUpperCase() + "%");
			} else {
				params.add("%" + documentopapel0.getNombreDoc13().toUpperCase() + "%");
			}
			where.append(" AND t1.NOMBRE_DOC_13 IS NOT NULL");
		}
		if (documentopapel0 != null && documentopapel0.getExtension13() != null) {
			where.append(" AND UPPER(t1.EXTENSION_13) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(documentopapel0.getExtension13().toUpperCase() + "%");
			} else {
				params.add("%" + documentopapel0.getExtension13().toUpperCase() + "%");
			}
			where.append(" AND t1.EXTENSION_13 IS NOT NULL");
		}
		if (documentopapel0 != null && documentopapel0.getUsuAlta13() != null) {
			where.append(" AND UPPER(t1.USU_ALTA_13) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(documentopapel0.getUsuAlta13().toUpperCase() + "%");
			} else {
				params.add("%" + documentopapel0.getUsuAlta13().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_ALTA_13 IS NOT NULL");
		}
		if (documentopapel0 != null && documentopapel0.getfAlta13() != null) {
			where.append(" AND t1.F_ALTA_13 = ?");
			params.add(documentopapel0.getfAlta13());
		}
		if (documentopapel0 != null && documentopapel0.getUsuModif13() != null) {
			where.append(" AND UPPER(t1.USU_MODIF_13) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(documentopapel0.getUsuModif13().toUpperCase() + "%");
			} else {
				params.add("%" + documentopapel0.getUsuModif13().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_MODIF_13 IS NOT NULL");
		}
		if (documentopapel0 != null && documentopapel0.getfModif13() != null) {
			where.append(" AND t1.F_MODIF_13 = ?");
			params.add(documentopapel0.getfModif13());
		}
		if (documentopapel0 != null && documentopapel0.getIdExpediente13() != null) {
			where.append(" AND t1.ID_EXPEDIENTE_13 = ?");
			params.add(documentopapel0.getIdExpediente13());
		}

		Map<String, Object> mapWhere = new HashMap<String, Object>();
		mapWhere.put("query", where);
		mapWhere.put("params", params);

		return mapWhere;
	}
}
