PartnerApiServiceImpl.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.v2.facade.impl;
import org.genesys.server.api.v2.facade.PartnerApiService;
import org.genesys.server.api.v2.model.impl.FaoInstituteDTO;
import org.genesys.server.api.v2.model.impl.PartnerDTO;
import org.genesys.server.api.v2.model.impl.PartnerInfo;
import org.genesys.server.exception.SearchException;
import org.genesys.server.model.Partner;
import org.genesys.server.model.filters.PartnerFilter;
import org.genesys.server.service.PartnerService;
import org.genesys.server.service.filter.InstituteFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@Service
@Transactional(readOnly = true)
public class PartnerApiServiceImpl extends APIFilteredServiceFacadeImpl<PartnerService, PartnerDTO, Partner, PartnerFilter> implements PartnerApiService {
@Override
protected Partner convert(PartnerDTO source) {
return mapper.map(source);
}
@Override
protected PartnerDTO convert(Partner source) {
return mapper.map(source);
}
@Override
@Transactional
public PartnerDTO create(PartnerDTO source) {
return super.create(source);
}
@Override
@Transactional
public PartnerDTO update(PartnerDTO updated) {
return super.update(updated);
}
@Override
@Transactional
public PartnerDTO remove(PartnerDTO entity) {
return super.remove(entity);
}
@Override
public PartnerDTO get(UUID uuid) {
return convert(service.get(uuid));
}
@Override
public PartnerDetails loadPartnerDetails(UUID uuid) {
return mapper.map(service.loadPartnerDetails(uuid));
}
@Override
public Page<FaoInstituteDTO> loadPartnerInstitutes(UUID uuid, InstituteFilter filter, Pageable page) {
return mapper.map(service.loadPartnerInstitutes(uuid, filter, page), mapper::map);
}
@Override
public Page<PartnerDTO> listPartnersForCurrentUser(PartnerFilter filter, Pageable page) {
return mapper.map(service.listPartnersForCurrentUser(filter, page), mapper::map);
}
@Override
@Transactional
public PartnerDTO addInstitutes(PartnerDTO partner, Set<String> instituteCodes) {
return convert(service.addInstitutes(convert(partner), instituteCodes));
}
@Override
@Transactional
public PartnerDTO removeInstitutes(UUID uuid, Set<String> instituteCodes) {
Partner partner = service.get(uuid);
return convert(service.removeInstitutes(partner, instituteCodes));
}
@Override
@Transactional
public PartnerDTO addInstitutes(UUID uuid, Set<String> instituteCodes) {
Partner partner = service.get(uuid);
return convert(service.addInstitutes(partner, instituteCodes));
}
@Override
@Transactional
public PartnerDTO deletePartner(UUID uuid, int version) {
return convert(service.remove(service.loadPartner(uuid, version)));
}
@Override
public Page<PartnerDTO> list(PartnerFilter filter, Pageable page) throws SearchException {
return mapper.map(service.list(filter, page), mapper::mapNoAudit);
}
@Override
public List<PartnerInfo> listAllPartners() {
return mapper.map(service.list(Pageable.unpaged()).getContent(), mapper::mapInfo);
}
@Override
public List<PartnerInfo> listMyPartners() {
return mapper.map(service.listAllPartnersForCurrentUser(), mapper::mapInfo);
}
}