2022-02-04 10:12:15 +01:00
|
|
|
package eu.dnetlib.openaire.community;
|
|
|
|
|
2023-06-12 14:47:27 +02:00
|
|
|
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;
|
2022-02-07 10:09:18 +01:00
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
2022-02-04 10:12:15 +01:00
|
|
|
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;
|
|
|
|
|
2022-02-07 10:09:18 +01:00
|
|
|
import com.google.common.base.Functions;
|
2022-02-04 10:12:15 +01:00
|
|
|
|
2022-02-07 10:09:18 +01:00
|
|
|
import eu.dnetlib.openaire.common.ISClient;
|
2023-06-12 14:47:27 +02:00
|
|
|
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;
|
2022-09-26 12:15:39 +02:00
|
|
|
|
2022-02-04 10:12:15 +01:00
|
|
|
@Component
|
|
|
|
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
2023-06-12 14:47:27 +02:00
|
|
|
@Deprecated
|
2022-02-07 10:09:18 +01:00
|
|
|
public class CommunityApiCore {// implements CommunityClient{
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(CommunityApiCore.class);
|
|
|
|
|
2023-06-21 12:02:45 +02:00
|
|
|
// @Autowired
|
2022-02-07 10:09:18 +01:00
|
|
|
private ISClient isClient;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private CommunityCommon cc;
|
|
|
|
|
|
|
|
public List<CommunitySummary> listCommunities() throws CommunityException {
|
|
|
|
return cc.listCommunities();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-05-10 17:44:19 +02:00
|
|
|
public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException {
|
2022-02-07 10:09:18 +01:00
|
|
|
return cc.getCommunity(id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-05-10 17:44:19 +02:00
|
|
|
public List<CommunityProject> getCommunityProjects(final String id) throws CommunityException, ResourceNotFoundException {
|
2022-02-07 10:09:18 +01:00
|
|
|
cc.getCommunity(id); // ensure the community exists.
|
|
|
|
return cc.getCommunityInfo(id, PROJECTS_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityProject(id, c));
|
|
|
|
}
|
|
|
|
|
2023-05-10 17:44:19 +02:00
|
|
|
public List<CommunityContentprovider> getCommunityContentproviders(final String id) throws CommunityException, ResourceNotFoundException {
|
2022-02-07 10:09:18 +01:00
|
|
|
cc.getCommunity(id); // ensure the community exists.
|
|
|
|
return cc.getCommunityInfo(id, CONTENTPROVIDERS_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityDataprovider(id, c));
|
|
|
|
}
|
2022-02-04 10:12:15 +01:00
|
|
|
|
2023-05-10 17:44:19 +02:00
|
|
|
public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(final String id) throws CommunityException, ResourceNotFoundException {
|
2022-02-04 10:12:15 +01:00
|
|
|
|
2022-02-07 10:09:18 +01:00
|
|
|
return cc.getCommunityZenodoCommunities(id);
|
|
|
|
}
|
|
|
|
|
2023-05-10 17:44:19 +02:00
|
|
|
public List<CommunityOrganization> getCommunityOrganizations(final String id) throws CommunityException, ResourceNotFoundException {
|
2022-02-07 10:09:18 +01:00
|
|
|
cc.getCommunity(id);
|
|
|
|
return cc.getCommunityInfo(id, ORGANIZATION_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityOrganization(id, c));
|
|
|
|
}
|
|
|
|
|
|
|
|
// HELPERS
|
|
|
|
|
2023-05-10 17:44:19 +02:00
|
|
|
private TreeMap<Integer, CommunityZenodoCommunity> getZenodoCommunityMap(final String id) throws CommunityException, ResourceNotFoundException {
|
2022-02-07 10:09:18 +01:00
|
|
|
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));
|
|
|
|
}
|
2022-02-04 10:12:15 +01:00
|
|
|
|
2022-02-07 10:09:18 +01:00
|
|
|
}
|