WebCooperatorServiceImpl.java

/*
 * Copyright 2020 Global Crop Diversity Trust
 *
 * 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.
 */
package org.gringlobal.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.gringlobal.custom.elasticsearch.SearchException;
import org.gringlobal.model.WebCooperator;
import org.gringlobal.persistence.WebCooperatorRepository;
import org.gringlobal.service.WebCooperatorService;
import org.gringlobal.service.filter.WebCooperatorFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Maxym Borodenko
 */
@Service
@Transactional(readOnly = true)
@Slf4j
public class WebCooperatorServiceImpl extends FilteredCRUDServiceImpl<WebCooperator, WebCooperatorFilter, WebCooperatorRepository> implements WebCooperatorService {

	@Override
	@Transactional
	public WebCooperator create(WebCooperator source) {
		log.debug("Create WebCooperator. Input data {}", source);
		WebCooperator webCooperator = new WebCooperator();
		webCooperator.apply(source);

		WebCooperator saved = repository.save(webCooperator);
		return _lazyLoad(saved);
	}

	@Override
	@Transactional
	public WebCooperator update(WebCooperator input, WebCooperator target) {
		log.debug("Update WebCooperator. Input data {}", input);
		target.apply(input);

		WebCooperator saved = repository.save(target);
		return _lazyLoad(saved);
	}

	@Override
	public Page<WebCooperator> list(WebCooperatorFilter filter, Pageable page) throws SearchException {
		return super.list(WebCooperator.class, filter, page);
	}
}