InventoryViabilityService.java

/*
 * Copyright 2021 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.Collection;
import java.util.List;
import java.util.Map;

import org.gringlobal.model.Cooperator;
import org.gringlobal.model.Inventory;
import org.gringlobal.model.InventoryViability;
import org.gringlobal.model.InventoryViabilityData;
import org.gringlobal.model.InventoryViabilityRule;
import org.gringlobal.model.OrderRequest;
import org.gringlobal.model.Site;
import org.gringlobal.service.filter.InventoryViabilityFilter;

import com.fasterxml.jackson.annotation.JsonUnwrapped;

import javax.validation.constraints.NotNull;

/**
 * The Interface InventoryViabilityService.
 */
public interface InventoryViabilityService extends FilteredCRUDService2<InventoryViability, InventoryViabilityFilter> {

	/**
	 * Set up viability tests for selected inventories.
	 *
	 * @param inventoriesAndRules the map of inventory and corresponding rule
	 * {#link {@link InventoryViabilityRule}
	 * @return the order request
	 */
	OrderRequest orderViabilityTest(Site site, Map<Inventory, InventoryViabilityRule> inventoriesAndRules, Cooperator viabilityCooperator);

	/**
	 * List {@link InventoryViabilityData} for selected inventoryViability
	 * @param inventoryViability
	 * @return
	 */
	InventoryViabilityDetails loadDetails(InventoryViability inventoryViability);

	/**
	 * Retruns a summarized version of viability results across replicates
	 * 
	 * @param inventoryViability record to analyze
	 * @param selectedReplicationNumbers select the replicates to use, if null or empty then all are used
	 * @return results for selected replicates
	 */
	InventoryViabilityDetails calculateResult(@NotNull InventoryViability inventoryViability, Collection<Integer> selectedReplicationNumbers);

	public static class InventoryViabilityDetails {
		public InventoryViabilityDetails(InventoryViability inventoryViability) {
			this.inventoryViability = inventoryViability;
		}

		@JsonUnwrapped
		public InventoryViability inventoryViability;

		public List<InventoryViabilityData> datas;
	}
}