package eu.dnetlib.openaire.community; import static eu.dnetlib.openaire.community.CommunityConstants.CONTENTPROVIDERS_ID_SUFFIX; import static eu.dnetlib.openaire.community.CommunityConstants.ORGANIZATION_ID_SUFFIX; import static eu.dnetlib.openaire.community.CommunityConstants.PROJECTS_ID_SUFFIX; import java.util.List; import java.util.TreeMap; import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; import com.google.common.base.Functions; import eu.dnetlib.openaire.common.ISClient; import eu.dnetlib.openaire.exporter.exceptions.CommunityException; import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException; import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider; import eu.dnetlib.openaire.exporter.model.community.CommunityDetails; import eu.dnetlib.openaire.exporter.model.community.CommunityOrganization; import eu.dnetlib.openaire.exporter.model.community.CommunityProject; import eu.dnetlib.openaire.exporter.model.community.CommunitySummary; import eu.dnetlib.openaire.exporter.model.community.CommunityZenodoCommunity; @Component @ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true") @Deprecated public class CommunityApiCore {// implements CommunityClient{ private static final Log log = LogFactory.getLog(CommunityApiCore.class); // @Autowired private ISClient isClient; @Autowired private CommunityCommon cc; public List listCommunities() throws CommunityException { return cc.listCommunities(); } public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException { return cc.getCommunity(id); } public List getCommunityProjects(final String id) throws CommunityException, ResourceNotFoundException { cc.getCommunity(id); // ensure the community exists. return cc.getCommunityInfo(id, PROJECTS_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityProject(id, c)); } public List getCommunityContentproviders(final String id) throws CommunityException, ResourceNotFoundException { cc.getCommunity(id); // ensure the community exists. return cc.getCommunityInfo(id, CONTENTPROVIDERS_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityDataprovider(id, c)); } public List getCommunityZenodoCommunities(final String id) throws CommunityException, ResourceNotFoundException { return cc.getCommunityZenodoCommunities(id); } public List getCommunityOrganizations(final String id) throws CommunityException, ResourceNotFoundException { cc.getCommunity(id); return cc.getCommunityInfo(id, ORGANIZATION_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityOrganization(id, c)); } // HELPERS private TreeMap getZenodoCommunityMap(final String id) throws CommunityException, ResourceNotFoundException { return getCommunityZenodoCommunities(id).stream() .collect(Collectors.toMap(cp -> Integer.valueOf(cp.getId()), Functions.identity(), (cp1, cp2) -> { log.warn(String.format("duplicate Zenodo community found: '%s'", cp1.getId())); return cp2; }, TreeMap::new)); } }