GenesysService.java

/**
 * Copyright 2014 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.genesys.server.service;

import java.io.OutputStream;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import org.genesys.server.model.genesys.Accession;
import org.genesys.server.model.genesys.AccessionAlias;
import org.genesys.server.model.genesys.AccessionCollect;
import org.genesys.server.model.genesys.AccessionData;
import org.genesys.server.model.genesys.AccessionHistoric;
import org.genesys.server.model.genesys.AccessionId;
import org.genesys.server.model.genesys.AccessionRemark;
import org.genesys.server.model.genesys.PDCI;
import org.genesys.server.model.genesys.PDCIStatistics;
import org.genesys.server.model.genesys.SvalbardDeposit;
import org.genesys.server.model.genesys.Taxonomy2;
import org.genesys.server.model.impl.AccessionIdentifier3;
import org.genesys.server.model.impl.Country;
import org.genesys.server.model.impl.Crop;
import org.genesys.server.model.impl.FaoInstitute;
import org.genesys.server.model.impl.PGRFANetwork;
import org.genesys.server.service.filter.AccessionFilter;
import org.genesys.server.exception.NonUniqueAccessionException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface GenesysService {

	/**
	 * Return the number of active ({@link Accession#historic} == false)
	 * accession records
	 */
	long countByInstitute(FaoInstitute institute);

	/**
	 * Return the number of active ({@link Accession#historic} == false) accession
	 * records with DOI
	 */
	long countByInstituteWithDoi(FaoInstitute institute);

	/**
	 * Return the number of active ({@link Accession#historic} == false) accession
	 * records
	 */
	long countByOrigin(Country country);

	/**
	 * Return the number of active ({@link Accession#historic} == false)
	 * accession records
	 */
	long countByLocation(Country country);

	Accession getAccession(long accessionId);

	/**
	 * Clear DOIs for accessions(set null in DOI field)
	 */
	void removeDOIs();

	Accession getAccessionByDOI(String doi);

	List<Accession> listAccessions(FaoInstitute faoInstitute, String accessionName);

	Page<Accession> listAccessions(Collection<Long> accessionIds, Pageable pageable);

	Accession getAccession(AccessionIdentifier3 aid3) throws NonUniqueAccessionException;

	Accession getAccession(String instCode, String doi, String acceNumb, String genus) throws NonUniqueAccessionException;

	Page<Object[]> statisticsCropNameByInstitute(FaoInstitute faoInstitute, Pageable pageRequest);

	Page<Object[]> statisticsGenusByInstitute(FaoInstitute faoInstitute, Pageable pageable);

	Page<Object[]> statisticsSpeciesByInstitute(FaoInstitute faoInstitute, Pageable pageable);

	List<Object[]> statisticsSpeciesByInstituteES(FaoInstitute faoInstitute, int size);

	// Page<Object[]> statisticsCropByInstitute(FaoInstitute faoInstitute,
	// Pageable pageable);

	List<Long> listAccessionsIds(Pageable pageable);

	Page<Accession> listAccessionsByOrganization(PGRFANetwork network, Pageable pageable);

	void updateAccessionCountryRefs();

	void updateAccessionInstitueRefs();

	List<Accession> saveAccessions(FaoInstitute institute, List<Accession> matching);

	long countAvailableForDistribution(Set<Long> accessionIds);

	Set<Long> filterAvailableForDistribution(Set<Long> accessionIds);

	List<Accession> saveAccessions(Iterable<Accession> accession);

	void updateAccessionCount(FaoInstitute institute);

	FaoInstitute updatePDCI(FaoInstitute institute);

	List<SvalbardDeposit> getSvalbardData(AccessionId accession);

	void writeAccessions(AccessionFilter filter, OutputStream outputStream, String shortFilter, String dataSource) throws Exception;

	List<AccessionHistoric> removeAccessions(FaoInstitute institute, List<Accession> toDelete);

	void addAccessions(List<Accession> accessions);

	long countAll();

	long countAllActive();

	long countAllHistoric();

	long countByCrop(Crop crop);
	
	/**
	 * For institutes with {@link FaoInstitute#uniqueAcceNumbs}
	 * 
	 * @param instCode
	 * @param acceNumb
	 * @return the 1 accession
	 * @throws NonUniqueAccessionException
	 */
	Accession getAccession(String instCode, String acceNumb) throws NonUniqueAccessionException;

	/**
	 * @param acceNumb
	 * @return list of accessions
	 */
	List<Accession> listAccessions(String acceNumb);

	List<FaoInstitute> findHoldingInstitutes(Set<Long> accessionIds);

	Set<Long> listAccessions(FaoInstitute holdingInstitute, Set<Long> accessionIds);

	List<Long> listAccessionsIds(Taxonomy2 taxonomy);

	public static class AllStuff {
		public AllStuff(long id) {
			this.id = id;
		}

		public AllStuff(AccessionData accession) {
			this.accession = accession;
			this.id = accession.getId();
		}

		public Long id;
		public AccessionData accession = null;
		public AccessionCollect collect = null;
		public List<AccessionAlias> names = null;
		public List<AccessionRemark> remarks = null;
		public List<SvalbardDeposit> sgsvDeposits = null;
	}

	List<AllStuff> loadAllStuff(Collection<Long> accessionIds);

	int assignMissingUuid(int count);

	AccessionHistoric getHistoricAccession(UUID uuid);

	List<PDCI> loadPDCI(List<Long> batch);

	PDCIStatistics statisticsPDCI(PGRFANetwork network);

	List<SvalbardDeposit> saveSvalbards(List<SvalbardDeposit> svalbards);
	
	List<Accession> updateAccessionCrops(Set<Long> accessionIds);

	List<Object[]> getLastUpdatedStatistics();

	List<Object[]> getLastUpdatedStatistics(FaoInstitute faoInstitute);
	
	List<Object[]> getLastUpdatedStatistics(FaoInstitute faoInstitute, boolean historic);

	List<AccessionData> listActiveAndHistoric(List<UUID> accessionUuids);

}