This commit is contained in:
Michele Artini 2023-07-03 12:15:37 +02:00
parent 60b7d82d47
commit 6f873b1e45
2 changed files with 33 additions and 5 deletions

View File

@ -51,8 +51,6 @@ import eu.dnetlib.openaire.exporter.model.context.ConceptSummary;
public class CommunityService { public class CommunityService {
// TODO: Verificare Tickets: #8835, #8854, #6483, #3259, #3494 // TODO: Verificare Tickets: #8835, #8854, #6483, #3259, #3494
// L'IMPORT DI ALCUNI PROGETTI FALLISCE perche' non hanno openaireID
// L'IMPORT DI ALCUNE ORGS DAL PROVISION WF FALLISCE perche' il communityID non esiste
@Autowired @Autowired
private DbCommunityRepository dbCommunityRepository; private DbCommunityRepository dbCommunityRepository;

View File

@ -19,12 +19,14 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import eu.dnetlib.miscutils.functional.hash.Hashing;
import eu.dnetlib.openaire.community.CommunityService; import eu.dnetlib.openaire.community.CommunityService;
import eu.dnetlib.openaire.community.model.DbOrganization; import eu.dnetlib.openaire.community.model.DbOrganization;
import eu.dnetlib.openaire.community.repository.DbOrganizationRepository; import eu.dnetlib.openaire.community.repository.DbOrganizationRepository;
@ -105,6 +107,9 @@ public class CommunityImporterService {
@Autowired @Autowired
private CommunityService service; private CommunityService service;
@Autowired
private JdbcTemplate jdbcTemplate;
private static final Log log = LogFactory.getLog(CommunityImporterService.class); private static final Log log = LogFactory.getLog(CommunityImporterService.class);
public List<DbOrganization> importPropagationOrganizationsFromProfile(final String xml, final boolean simulation) throws Exception { public List<DbOrganization> importPropagationOrganizationsFromProfile(final String xml, final boolean simulation) throws Exception {
@ -141,10 +146,28 @@ public class CommunityImporterService {
final List<CommunityContentprovider> datasources = final List<CommunityContentprovider> datasources =
getCommunityInfo(context, CONTENTPROVIDERS_ID_SUFFIX, c -> asCommunityDataprovider(context.getId(), c)); getCommunityInfo(context, CONTENTPROVIDERS_ID_SUFFIX, c -> asCommunityDataprovider(context.getId(), c));
// TODO: REMOVE THIS FILTER ?
final List<CommunityProject> projects = final List<CommunityProject> projects =
getCommunityInfo(context, PROJECTS_ID_SUFFIX, c -> asCommunityProject(context.getId(), c)) getCommunityInfo(context, PROJECTS_ID_SUFFIX, c -> asCommunityProject(context.getId(), c))
.stream() .stream()
.map(p -> {
if (p.getOpenaireId() == null) {
if (p.getFunder().equalsIgnoreCase("EC")) {
final String ns = findNamespaceForECProject(p.getGrantId());
if (ns != null) {
p.setOpenaireId(ns + "::" + Hashing.md5(p.getGrantId()));
} else {
log.error("EC project not in the db: " + p.getGrantId());
}
} else if (p.getFunder().equalsIgnoreCase("NSF")) {
p.setOpenaireId("nsf_________::" + Hashing.md5(p.getGrantId()));
} else if (p.getFunder().equalsIgnoreCase("NIH")) {
p.setOpenaireId("nih_________::" + Hashing.md5(p.getGrantId()));
} else {
log.warn("Openaire ID is missing, funder: " + p.getFunder());
}
}
return p;
})
.filter(p -> p.getOpenaireId() != null) .filter(p -> p.getOpenaireId() != null)
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -173,7 +196,9 @@ public class CommunityImporterService {
service.addCommunityContentProvidersList(context.getId(), datasources); service.addCommunityContentProvidersList(context.getId(), datasources);
service.addCommunityOrganizationList(context.getId(), orgs); service.addCommunityOrganizationList(context.getId(), orgs);
service.addSubCommunityList(subs); service.addSubCommunityList(subs);
} catch (final Exception e) { } catch (
final Exception e) {
throw new RuntimeException("Error importing community: " + context.getId(), e); throw new RuntimeException("Error importing community: " + context.getId(), e);
} }
} }
@ -278,7 +303,6 @@ public class CommunityImporterService {
final Map<String, List<Param>> p = c.getParams(); final Map<String, List<Param>> p = c.getParams();
final CommunityOrganization o = new CommunityOrganization(); final CommunityOrganization o = new CommunityOrganization();
o.setCommunityId(id); o.setCommunityId(id);
// o.setId(StringUtils.substringAfterLast(c.getId(), ID_SEPARATOR));
o.setName(firstValue(p, CORGANIZATION_NAME)); o.setName(firstValue(p, CORGANIZATION_NAME));
o.setLogo_url(getDecodedUrl(firstValue(p, CORGANIZATION_LOGOURL))); o.setLogo_url(getDecodedUrl(firstValue(p, CORGANIZATION_LOGOURL)));
o.setWebsite_url(getDecodedUrl(firstValue(p, CORGANIZATION_WEBSITEURL))); o.setWebsite_url(getDecodedUrl(firstValue(p, CORGANIZATION_WEBSITEURL)));
@ -306,6 +330,12 @@ public class CommunityImporterService {
return list; return list;
} }
private String findNamespaceForECProject(final String code) {
final List<String> list =
jdbcTemplate.queryForList("SELECT substr(id, 1, 12) from projects where code = ? and id like 'corda%'", String.class, code);
return list.isEmpty() ? null : list.get(0);
}
private static String getDecodedUrl(final String encoded_url) { private static String getDecodedUrl(final String encoded_url) {
if (encoded_url == null) { return encoded_url; } if (encoded_url == null) { return encoded_url; }
return new String(Base64.getDecoder().decode(encoded_url)); return new String(Base64.getDecoder().decode(encoded_url));