CropTraitObservationDataService.java

package org.gringlobal.service;

import java.util.List;
import java.util.Objects;
import java.util.Set;

import org.gringlobal.api.v1.impl.CropTraitObservationController;
import org.gringlobal.model.CropTrait;
import org.gringlobal.model.CropTraitObservation;
import org.gringlobal.model.CropTraitObservationData;
import org.gringlobal.model.Inventory;
import org.gringlobal.model.Method;
import org.gringlobal.service.filter.CropTraitObservationDataFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;


public interface CropTraitObservationDataService extends FilteredCRUDService<CropTraitObservationData, CropTraitObservationDataFilter> {


	/**
	 * We generate CTO records based on raw CTOD. These records are not persisted!
	 */
	List<CropTraitObservation> generateObservations(Method method, CropTrait cropTrait);

	FilteredObservationsData search(CropTraitObservationDataFilter filter, Pageable page);

	Page<Inventory> getObservationDataInventoriesByMethod(Long methodId, Pageable pageable);

	Page<CropTrait> getObservationDataTraitsByMethod(Long methodId, Pageable pageable);

	int ensureObservationData(CropTraitObservationController.EnsureObservationsRequest request);

	class FilteredObservationsData {
		public Set<Method> methods;
		public Set<CropTraitTranslationService.TranslatedCropTrait> cropTraits;
		public Set<InventoryWithObservationsData> observationsData;

		/** The filter. */
		public CropTraitObservationDataFilter filter;
	}

	class InventoryWithObservationsData {
		public Inventory i;
		public Set<CropTraitObservationData> o;

		public InventoryWithObservationsData(Inventory i, Set<CropTraitObservationData> o) {
			this.i = i;
			this.o = o;
		}

		@Override
		public boolean equals(Object o1) {
			if (this == o1) return true;
			if (o1 == null || getClass() != o1.getClass()) return false;
			InventoryWithObservationsData that = (InventoryWithObservationsData) o1;
			return Objects.equals(i, that.i) && Objects.equals(o.size(), that.o.size());
		}

		@Override
		public int hashCode() {
			return Objects.hash(i, o);
		}
	}

}