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

Java tutorial

Introduction

Here is the source code for com.dominion.salud.mpr.negocio.service.maestros.impl.PautasServiceImpl.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.Pautas;
import com.dominion.salud.mpr.negocio.repositories.maestros.PautasRepository;
import com.dominion.salud.mpr.negocio.service.maestros.PautasService;
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("pautasService")
public class PautasServiceImpl extends AbstractMaestrosServiceImpl<Pautas, Long> implements PautasService {

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

    @Autowired
    private PautasRepository pautasRepository;

    @Override
    public Pautas findByCodPauta(Pautas pautas) {
        return pautasRepository.findByCodPauta(pautas);
    }

    @Override
    public Pautas findByCodPautaAndInsert(Pautas pautas) {
        try {
            if (StringUtils.isNotBlank(pautas.getCodPauta()) && StringUtils.isNotBlank(pautas.getTxtPauta())) {
                logger.debug("          Buscando PAUTAS (" + pautas.getCodPauta() + ") " + pautas.getTxtPauta());
                return pautasRepository.findByCodPauta(pautas);
            }
        } catch (NoResultException nre) {
            logger.debug("          No se ha encontrado registro, insertando PAUTAS (" + pautas.getCodPauta() + ") "
                    + pautas.getTxtPauta());
            return pautasRepository.save(pautas);
        }
        return null;
    }
}