GeographyServiceImpl.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.Geography;
import org.gringlobal.persistence.GeographyRepository;
import org.gringlobal.service.GeographyService;
import org.gringlobal.service.filter.GeographyFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * The Class GeographyServiceImpl.
 */
@Service
@Transactional(readOnly = true)
@Slf4j
public class GeographyServiceImpl extends FilteredCRUDServiceImpl<Geography, GeographyFilter, GeographyRepository> implements GeographyService {

	@Override
	@Transactional
	@PreAuthorize("@ggceSec.actionAllowed('GeographyData', 'CREATE')")
	public Geography create(Geography source) {
		log.debug("Create Geography. Input data {}", source);
		Geography geography = new Geography();
		geography.apply(source);

		Geography saved = repository.save(geography);
		saved.lazyLoad();

		return saved;
	}

	@Override
	@Transactional
	@PreAuthorize("@ggceSec.actionAllowed('GeographyData', 'WRITE')")
	public Geography update(Geography updated) {
		return super.update(updated);
	}

	@Override
	@Transactional
	@PreAuthorize("@ggceSec.actionAllowed('GeographyData', 'WRITE')")
	public Geography update(Geography updated, Geography target) {
		log.debug("Update Geography. Input data {}", updated);
		target.apply(updated);

		Geography saved = repository.save(target);
		saved.lazyLoad();
		return saved;
	}

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

	@Override
	@Transactional
	@PreAuthorize("@ggceSec.actionAllowed('GeographyData', 'DELETE')")
	public Geography remove(Geography entity) {
		return super.remove(entity);
	}
}