PartnerService.java
/*
* Copyright 2018 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.util.List;
import java.util.Set;
import java.util.UUID;
import org.genesys.server.model.Partner;
import org.genesys.server.model.dataset.Dataset;
import org.genesys.server.model.filters.PartnerFilter;
import org.genesys.server.model.impl.FaoInstitute;
import org.genesys.server.model.impl.Subset;
import org.genesys.server.model.traits.DescriptorList;
import org.genesys.server.service.filter.InstituteFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
/**
* Services for Partner.
*
* @author Andrey Lugovskoy
* @author Matija Obreza
*/
public interface PartnerService extends FilteredCRUDService2<Partner, PartnerFilter> {
/**
* Gets the primary partner.
*
* @return the primary partner
*/
Partner getPrimaryPartner();
/**
* Autocomplete partners.
*
* @param term the term
* @param limit maximum number of results
* @return list of partners
*/
List<Partner> autocompletePartners(String term, int limit);
/**
* Get partner by uuid
*
* @param uuid uuid of partner
* @return the partner
*/
Partner get(UUID uuid);
/**
* Load partner by uuid of partner.
*
* @param uuid uuid of partner
* @return found partner
*/
Partner load(UUID uuid);
/**
* Load partner details by uuid of partner.
*
* @param uuid uuid of partner
* @return found partner
*/
PartnerDetails loadPartnerDetails(UUID uuid);
/**
* Load partners institutes by uuid of partner.
*
* @param uuid uuid of partner
* @return partners institutes
*/
Page<FaoInstitute> loadPartnerInstitutes(UUID uuid, InstituteFilter filter, Pageable page);
/**
* Load partners institutes by uuids of partners.
*
* @param partnersUUIDs the list of partners UUIDs
* @return list of institutes
*/
Set<FaoInstitute> loadInstitutes(Set<UUID> partnersUUIDs);
/**
* Load partner.
*
* @param uuid the uuid
* @param version the version
* @return the partner
*/
Partner loadPartner(UUID uuid, int version);
/**
* Load page for Partners by current user.
*
* @param filter the filter
* @param page page with parameters
* @return page partners
*/
Page<Partner> listPartnersForCurrentUser(PartnerFilter filter, Pageable page);
/**
* Load all Partners by current user.
*
* @return list partners
*/
List<Partner> listAllPartnersForCurrentUser();
/**
* Adds the institutes to partner
*
* @param partner the partner
* @param instituteCodes the institute codes
* @return the partner
*/
Partner addInstitutes(Partner partner, Set<String> instituteCodes);
/**
* Removes the institutes from partner
*
* @param partner the partner
* @param instituteCodes the institute codes
* @return the partner
*/
Partner removeInstitutes(Partner partner, Set<String> instituteCodes);
long countPartners(PartnerFilter filter);
class PartnerDetails {
@JsonUnwrapped
public Partner details;
public List<Subset> recentSubsets;
public List<Dataset> recentDatasets;
public List<DescriptorList> recentDescriptorLists;
public static PartnerDetails from(Partner partner, List<Subset> recentSubsets,List<Dataset> recentDatasets, List<DescriptorList> recentDescriptorLists) {
PartnerDetails partnerDetails = new PartnerDetails();
partnerDetails.details = partner;
partnerDetails.recentSubsets = recentSubsets;
partnerDetails.recentDatasets = recentDatasets;
partnerDetails.recentDescriptorLists = recentDescriptorLists;
return partnerDetails;
}
}
}