com.dominion.salud.mpr.negocio.service.maestros.impl.SexosServiceImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.dominion.salud.mpr.negocio.service.maestros.impl.SexosServiceImpl.java

Source

/*
 * 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.mpr.negocio.service.maestros.impl;

import com.dominion.salud.mpr.negocio.entities.maestros.Sexos;
import com.dominion.salud.mpr.negocio.repositories.maestros.SexosRepository;
import com.dominion.salud.mpr.negocio.service.maestros.SexosService;
import javax.persistence.NoResultException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author jcgonzalez
 */
@Service("sexosService")
public class SexosServiceImpl extends AbstractMaestrosServiceImpl<Sexos, Long> implements SexosService {

    private static final Logger logger = LoggerFactory.getLogger(SexosServiceImpl.class);

    @Autowired
    private SexosRepository sexosRepository;

    @Override
    public Sexos findByCodSexo(Sexos sexos) {
        return sexosRepository.findByCodSexo(sexos);
    }

    @Override
    public Sexos findByCodSexoAndInsert(Sexos sexos) {
        try {
            if (StringUtils.isNotBlank(sexos.getCodSexo()) && StringUtils.isNotBlank(sexos.getTxtSexo())) {
                logger.debug("          Buscando SEXOS (" + sexos.getCodSexo() + ") " + sexos.getTxtSexo());
                return sexosRepository.findByCodSexo(sexos);
            }
        } catch (NoResultException nre) {
            logger.debug("          No se ha encontrado registro, insertando SEXOS (" + sexos.getCodSexo() + ") "
                    + sexos.getTxtSexo());
            return sexosRepository.save(sexos);
        }
        return null;
    }
}