CropService.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;

import java.util.List;

import org.gringlobal.model.*;
import org.gringlobal.service.filter.CropFilter;
import org.gringlobal.service.filter.TaxonomySpeciesFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.fasterxml.jackson.annotation.JsonUnwrapped;

import javax.validation.constraints.NotNull;

/**
 * The Interface CropService.
 */
public interface CropService extends FilteredCRUDService<Crop, CropFilter> {

	/**
	 * Gets the crop.
	 *
	 * @param cropName the crop name
	 * @return the crop
	 */
	Crop getCrop(String cropName);

	/**
	 * Ensure crop taxonomy link.
	 *
	 * @param crop the crop
	 * @param taxonomySpecies the taxonomy species
	 * @return the taxonomy crop map
	 */
	TaxonomyCropMap ensureCropTaxonomyLink(Crop crop, TaxonomySpecies taxonomySpecies);

	/**
	 * Gets the crop details.
	 *
	 * @param crop the crop
	 * @return the crop details
	 */
	CropDetails getCropDetails(Crop crop);

	/**
	 * Adding taxonomy species to the crop.
	 *
	 * @param crop the crop
	 * @param species the list of taxonomy species
	 * @param note the note
	 * @return added records
	 */
	List<TaxonomyCropMap> addSpecies(@NotNull Crop crop, List<TaxonomySpecies> species, String note);

	/**
	 * Removing taxonomy species for the crop.
	 *
	 * @param crop the crop
	 * @param species the list of taxonomy species
	 * @return removed records
	 */
	List<TaxonomyCropMap> removeSpecies(Crop crop, List<TaxonomySpecies> species);

	class CropDetails {
		@JsonUnwrapped
		public Crop crop;

		public List<CropAttach> attachments;
	}


	/**
	 * List {@link TaxonomySpecies} associated with the crop.
	 *
	 * @param crop the crop
	 * @param filter the filter
	 * @param pageable the pageable
	 * @return the page
	 */
	Page<TaxonomySpecies> listSpecies(Crop crop, TaxonomySpeciesFilter filter, Pageable pageable);

	/**
	 * Auto-complete crops.
	 *
	 * @param term the search term
	 * @return matching crops list
	 */
	List<Crop> autocompleteCrops(String term);

	/**
	 * List of all crops
	 *
	 * @param pageable the pageable
	 * @return crops list
	 */
	Page<Crop> listCrops(Pageable pageable);

}