Java tutorial
/* * Copyright (C) 2016 Dominion Global * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.dominion.salud.pedicom.negocio.repositories.impl; import static com.dominion.salud.pedicom.negocio.configuration.CriptoManager.encriptar; import com.dominion.salud.pedicom.negocio.entities.LinParInt; import com.dominion.salud.pedicom.negocio.entities.Usuarios; import com.dominion.salud.pedicom.negocio.repositories.LinParIntRepository; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; /** * * @author jcgonzalez */ @Repository("usuariosRepository") public class UsuariosRepositoryImpl { @PersistenceContext(unitName = "MainEM") private EntityManager entityManager; @Autowired private LinParIntRepository linParIntRepository; public Usuarios validarUsuarios(Usuarios usuarios) { List<LinParInt> list = linParIntRepository.getModulos(); String pass = usuarios.getPasswUsu(); String encriptado = "N"; for (LinParInt lin : list) { if (lin.getLinParIntPK().getTipo().equals("ENCRIPTADO")) { encriptado = StringUtils.trim(lin.getParametro()); } } if (encriptado.equals("S")) { pass = encriptar(usuarios.getPasswUsu()); } return (Usuarios) entityManager .createQuery("from Usuarios where loginUsu = :loginUsu and passwUsu = :passwUsu", Usuarios.class) .setParameter("loginUsu", usuarios.getLoginUsu()).setParameter("passwUsu", pass).getSingleResult(); } public Usuarios validarCentroUsuarios(Usuarios usuarios) { return (Usuarios) entityManager .createQuery( "from Usuarios where loginUsu = :loginUsu and (centroUsu = :centroUsu or centroUsu = 0)", Usuarios.class) .setParameter("loginUsu", usuarios.getLoginUsu()).setParameter("centroUsu", usuarios.getCentroUsu()) .getSingleResult(); } public Usuarios findUsuariosByLogin(Usuarios usuarios) { return (Usuarios) entityManager.createQuery("from Usuarios where loginUsu = :loginUsu", Usuarios.class) .setParameter("loginUsu", usuarios.getLoginUsu()).getSingleResult(); } }