CropApiServiceImpl.java
/*
* Copyright 2024 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.v1.facade.impl;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.server.api.v1.facade.CropApiService;
import org.genesys.server.api.v1.mapper.APIv1Mapper;
import org.genesys.server.api.v1.model.Article;
import org.genesys.server.api.v1.model.Crop;
import org.genesys.server.api.v1.model.CropDetails;
import org.genesys.server.service.CRMException;
import org.genesys.server.service.CropService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.List;
import java.util.Locale;
@Service("cropV1APIService")
@Validated
@Transactional(readOnly = true)
public class CropApiServiceImpl implements CropApiService {
@Autowired
private APIv1Mapper mapper;
@Autowired
private CropService cropService;
@Override
public Crop getCrop(String shortName) {
return mapper.map(cropService.getCrop(shortName));
}
@Override
public CropDetails getDetails(String shortName, Locale locale) throws InvalidRepositoryPathException {
return mapper.map(cropService.getDetails(shortName, locale));
}
@Override
public List<CropDetails> listDetails() {
return mapper.map(cropService.listDetails(Locale.ENGLISH), mapper::map);
}
@Override
public List<Crop> listCrops() {
return mapper.map(cropService.listCrops(), mapper::map);
}
@Override
public List<Crop> list(Locale locale) {
return mapper.map(cropService.list(locale), mapper::map);
}
@Override
@Transactional
public Article updateBlurb(Crop crop, String title, String summary, String textBody, Locale locale) throws CRMException {
return mapper.map(cropService.updateBlurb(mapper.map(crop), title, summary, textBody, locale));
}
@Override
@Transactional
public Crop addCrop(String shortName, String name, String description) {
return mapper.map(cropService.addCrop(shortName, name, description));
}
@Override
@Transactional
public Crop updateCrop(Crop crop, String name, String description) {
return mapper.map(cropService.updateCrop(mapper.map(crop), name, description));
}
@Override
public List<Crop> getCrops(List<String> cropNames) {
return mapper.map(cropService.getCrops(cropNames), mapper::map);
}
@Override
@Transactional
public Crop updateAliases(Crop crop, List<String> otherNames) {
return mapper.map(cropService.updateAliases(mapper.map(crop), otherNames));
}
@Override
@Transactional
public void unlinkAccessionsForCrop(Crop crop) {
cropService.unlinkAccessionsForCrop(mapper.map(crop));
}
@Override
@Transactional
public void linkAccessionsWithCrop(Crop crop) {
cropService.linkAccessionsWithCrop(mapper.map(crop));
}
@Override
@Transactional
public Crop create(Crop cropJson) {
return mapper.map(cropService.create(mapper.map(cropJson)));
}
@Override
@Transactional
public Crop update(Crop cropJson) {
return mapper.map(cropService.update(mapper.map(cropJson)));
}
@Override
@Transactional
public Crop remove(Crop crop) {
return mapper.map(cropService.remove(mapper.map(crop)));
}
}