package eu.dnetlib.openaire.community; import java.util.List; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import eu.dnetlib.openaire.community.db.CommunityService; import eu.dnetlib.openaire.exporter.exceptions.CommunityException; 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; @RestController public class CommunityImporterController { @Autowired private CommunityService service; @Autowired private CommunityApiCore core; @GetMapping("/community_importer/import") public List importProfiles() throws CommunityException { final List list = core.listCommunities() .stream() .map(c -> c.getId()) .collect(Collectors.toList()); list.forEach(this::importCommunity); return list; } private void importCommunity(final String id) { try { final CommunityDetails community = core.getCommunity(id); final List datasources = core.getCommunityContentproviders(id); final List projects = core.getCommunityProjects(id); final List orgs = core.getCommunityOrganizations(id); service.saveCommunity(community); service.addCommunityProjectList(id, projects); service.addCommunityContentProvidersList(id, datasources); service.addCommunityOrganizationList(id, orgs); // TODO MANAGE new fields and tables } catch (final Exception e) { throw new RuntimeException("Error importing community: " + id, e); } } }