EntityWithServiceImplAndDTOServiceImpl.java

package io.github.jhipster.sample.service.impl;

/*-
 * #%L
 * Jhipster Sample Application
 * %%
 * Copyright (C) 2017 Osgiliath
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import io.github.jhipster.sample.service.EntityWithServiceImplAndDTOService;
import io.github.jhipster.sample.domain.EntityWithServiceImplAndDTO;
import io.github.jhipster.sample.repository.EntityWithServiceImplAndDTORepository;
import io.github.jhipster.sample.service.dto.EntityWithServiceImplAndDTODTO;
import io.github.jhipster.sample.service.mapper.EntityWithServiceImplAndDTOMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Service Implementation for managing EntityWithServiceImplAndDTO.
 */
@Service
@Transactional
public class EntityWithServiceImplAndDTOServiceImpl implements EntityWithServiceImplAndDTOService{

    private final Logger log = LoggerFactory.getLogger(EntityWithServiceImplAndDTOServiceImpl.class);

    private final EntityWithServiceImplAndDTORepository entityWithServiceImplAndDTORepository;

    private final EntityWithServiceImplAndDTOMapper entityWithServiceImplAndDTOMapper;

    public EntityWithServiceImplAndDTOServiceImpl(EntityWithServiceImplAndDTORepository entityWithServiceImplAndDTORepository, EntityWithServiceImplAndDTOMapper entityWithServiceImplAndDTOMapper) {
        this.entityWithServiceImplAndDTORepository = entityWithServiceImplAndDTORepository;
        this.entityWithServiceImplAndDTOMapper = entityWithServiceImplAndDTOMapper;
    }

    /**
     * Save a entityWithServiceImplAndDTO.
     *
     * @param entityWithServiceImplAndDTODTO the entity to save
     * @return the persisted entity
     */
    @Override
    public EntityWithServiceImplAndDTODTO save(EntityWithServiceImplAndDTODTO entityWithServiceImplAndDTODTO) {
        log.debug("Request to save EntityWithServiceImplAndDTO : {}", entityWithServiceImplAndDTODTO);
        EntityWithServiceImplAndDTO entityWithServiceImplAndDTO = entityWithServiceImplAndDTOMapper.toEntity(entityWithServiceImplAndDTODTO);
        entityWithServiceImplAndDTO = entityWithServiceImplAndDTORepository.save(entityWithServiceImplAndDTO);
        return entityWithServiceImplAndDTOMapper.toDto(entityWithServiceImplAndDTO);
    }

    /**
     * Get all the entityWithServiceImplAndDTOS.
     *
     * @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public List<EntityWithServiceImplAndDTODTO> findAll() {
        log.debug("Request to get all EntityWithServiceImplAndDTOS");
        return entityWithServiceImplAndDTORepository.findAll().stream()
            .map(entityWithServiceImplAndDTOMapper::toDto)
            .collect(Collectors.toCollection(LinkedList::new));
    }

    /**
     * Get one entityWithServiceImplAndDTO by id.
     *
     * @param id the id of the entity
     * @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public EntityWithServiceImplAndDTODTO findOne(Long id) {
        log.debug("Request to get EntityWithServiceImplAndDTO : {}", id);
        EntityWithServiceImplAndDTO entityWithServiceImplAndDTO = entityWithServiceImplAndDTORepository.findOne(id);
        return entityWithServiceImplAndDTOMapper.toDto(entityWithServiceImplAndDTO);
    }

    /**
     * Delete the entityWithServiceImplAndDTO by id.
     *
     * @param id the id of the entity
     */
    @Override
    public void delete(Long id) {
        log.debug("Request to delete EntityWithServiceImplAndDTO : {}", id);
        entityWithServiceImplAndDTORepository.delete(id);
    }
}