GenotypeApiServiceImpl.java

/*
 * Copyright 2025 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.api.v2.facade.impl;

import org.genesys.server.api.v2.MultiOp;
import org.genesys.server.api.v2.facade.GenotypeApiService;
import org.genesys.server.api.v2.model.impl.GenotypeDTO;
import org.genesys.server.exception.SearchException;
import org.genesys.server.model.impl.Genotype;
import org.genesys.server.service.GenotypeService;
import org.genesys.server.service.filter.AccessionFilter;
import org.genesys.server.service.filter.GenotypeFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;

import java.io.InputStream;

@Service
@Validated
@Transactional(readOnly = true)
public class GenotypeApiServiceImpl extends APIFilteredServiceFacadeImpl<GenotypeService, GenotypeDTO, Genotype, GenotypeFilter> implements GenotypeApiService {

	@Override
	protected Genotype convert(GenotypeDTO source) {
		return mapper.map(source);
	}

	@Override
	protected GenotypeDTO convert(Genotype source) {
		return mapper.map(source);
	}

	@Transactional
	@Override
	public MultiOp<GenotypeDTO> remove(GenotypeFilter filter) {
		return mapper.map(service.remove(filter), this::convert);
	}

	@Override
	@Transactional
	public void uploadGenotypeIDs(InputStream inputStream, char separator, char quotechar) throws Exception {
		service.uploadGenotypeIDs(inputStream, separator, quotechar);
	}

	@Override
	public Page<GenotypeDTO> listGenotypes(AccessionFilter filter, Pageable page) throws SearchException {
		GenotypeFilter genotypeFilter = (GenotypeFilter) new GenotypeFilter()
			.accession(filter);
		return mapper.map(service.listGenotypes(genotypeFilter, page), this::convert);
	}
}