new_model_for_communities #15

Merged
michele.artini merged 81 commits from new_model_for_communities into master 2023-10-24 08:12:26 +02:00
7 changed files with 111 additions and 208 deletions
Showing only changes of commit f071321b3d - Show all commits

View File

@ -1,82 +0,0 @@
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<CommunitySummary> listCommunities() throws CommunityException {
return cc.listCommunities();
}
public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException {
return cc.getCommunity(id);
}
public List<CommunityProject> 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<CommunityContentprovider> 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<CommunityZenodoCommunity> getCommunityZenodoCommunities(final String id) throws CommunityException, ResourceNotFoundException {
return cc.getCommunityZenodoCommunities(id);
}
public List<CommunityOrganization> 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<Integer, CommunityZenodoCommunity> 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));
}
}

View File

@ -1,24 +1,10 @@
package eu.dnetlib.openaire.community;
import static eu.dnetlib.openaire.community.CommunityConstants.CPROFILE_ADVANCED_CONSTRAINT;
import static eu.dnetlib.openaire.community.CommunityConstants.CPROFILE_FOS;
import static eu.dnetlib.openaire.community.CommunityConstants.CPROFILE_SDG;
import static eu.dnetlib.openaire.community.CommunityConstants.CPROFILE_SUBJECT;
import static eu.dnetlib.openaire.community.CommunityConstants.CSUMMARY_DESCRIPTION;
import static eu.dnetlib.openaire.community.CommunityConstants.CSUMMARY_LOGOURL;
import static eu.dnetlib.openaire.community.CommunityConstants.CSUMMARY_NAME;
import static eu.dnetlib.openaire.community.CommunityConstants.CSUMMARY_STATUS;
import static eu.dnetlib.openaire.community.CommunityConstants.CSUMMARY_ZENODOC;
import static eu.dnetlib.openaire.community.CommunityConstants.CSV_DELIMITER;
import static eu.dnetlib.openaire.community.CommunityConstants.CZENODOCOMMUNITY_ID;
import static eu.dnetlib.openaire.community.CommunityConstants.ID_SEPARATOR;
import static eu.dnetlib.openaire.community.CommunityConstants.ZENODOCOMMUNITY_ID_SUFFIX;
import static eu.dnetlib.openaire.community.CommunityConstants.communityBlackList;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -28,6 +14,7 @@ import org.springframework.stereotype.Component;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import eu.dnetlib.openaire.common.ISClient;
@ -46,6 +33,57 @@ import eu.dnetlib.openaire.exporter.model.context.Param;
@Deprecated
public class CommunityCommon {
public final static Set<String> communityBlackList = Sets.newHashSet("fet-fp7", "fet-h2020");
// common
public final static String OPENAIRE_ID = "openaireId";
public final static String PIPE_SEPARATOR = "||";
public final static String ID_SEPARATOR = "::";
public final static String CSV_DELIMITER = ",";
public final static String CLABEL = "label";
// id suffixes
public final static String PROJECTS_ID_SUFFIX = ID_SEPARATOR + "projects";
public final static String CONTENTPROVIDERS_ID_SUFFIX = ID_SEPARATOR + "contentproviders";
public final static String ZENODOCOMMUNITY_ID_SUFFIX = ID_SEPARATOR + "zenodocommunities";
public final static String ORGANIZATION_ID_SUFFIX = ID_SEPARATOR + "organizations";
// community summary
public final static String CSUMMARY_DESCRIPTION = "description";
public final static String CSUMMARY_LOGOURL = "logourl";
public final static String CSUMMARY_STATUS = "status";
public final static String CSUMMARY_NAME = "name";
public final static String CSUMMARY_MANAGER = "manager";
public final static String CSUMMARY_ZENODOC = "zenodoCommunity";
// community profile
public final static String CPROFILE_SUBJECT = "subject";
public final static String CPROFILE_CREATIONDATE = "creationdate";
public final static String CPROFILE_FOS = "fos";
public final static String CPROFILE_SDG = "sdg";
public final static String CPROFILE_ADVANCED_CONSTRAINT = "advancedConstraints";
// community project
public final static String CPROJECT_FUNDER = "funder";
public final static String CPROJECT_NUMBER = "CD_PROJECT_NUMBER";
public final static String CPROJECT_FULLNAME = "projectfullname";
public final static String CPROJECT_ACRONYM = "acronym";
// community content provider
public final static String CCONTENTPROVIDER_NAME = "name";
public final static String CCONTENTPROVIDER_OFFICIALNAME = "officialname";
public final static String CCONTENTPROVIDER_ENABLED = "enabled";
public final static String CCONTENTPROVIDERENABLED_DEFAULT = "true";
public final static String CCONTENTPROVIDER_SELCRITERIA = "selcriteria";
// community zenodo community
public final static String CZENODOCOMMUNITY_ID = "zenodoid";
// community organization
public final static String CORGANIZATION_NAME = "name";
public final static String CORGANIZATION_LOGOURL = "logourl";
public final static String CORGANIZATION_WEBSITEURL = "websiteurl";
@Autowired
private ISClient isClient;
@ -81,7 +119,7 @@ public class CommunityCommon {
public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException {
final Context context = getContextMap().get(id);
if (context == null || CommunityConstants.communityBlackList.contains(id)) {
if (context == null || communityBlackList.contains(id)) {
// ResponseStatusException(NOT_FOUND, "Unable to find resource");
throw new ResourceNotFoundException();
}

View File

@ -1,61 +0,0 @@
package eu.dnetlib.openaire.community;
import java.util.Set;
import com.google.common.collect.Sets;
@Deprecated
public class CommunityConstants {
public final static Set<String> communityBlackList = Sets.newHashSet("fet-fp7", "fet-h2020");
// common
public final static String OPENAIRE_ID = "openaireId";
public final static String PIPE_SEPARATOR = "||";
public final static String ID_SEPARATOR = "::";
public final static String CSV_DELIMITER = ",";
public final static String CLABEL = "label";
// id suffixes
public final static String PROJECTS_ID_SUFFIX = ID_SEPARATOR + "projects";
public final static String CONTENTPROVIDERS_ID_SUFFIX = ID_SEPARATOR + "contentproviders";
public final static String ZENODOCOMMUNITY_ID_SUFFIX = ID_SEPARATOR + "zenodocommunities";
public final static String ORGANIZATION_ID_SUFFIX = ID_SEPARATOR + "organizations";
// community summary
public final static String CSUMMARY_DESCRIPTION = "description";
public final static String CSUMMARY_LOGOURL = "logourl";
public final static String CSUMMARY_STATUS = "status";
public final static String CSUMMARY_NAME = "name";
public final static String CSUMMARY_MANAGER = "manager";
public final static String CSUMMARY_ZENODOC = "zenodoCommunity";
// community profile
public final static String CPROFILE_SUBJECT = "subject";
public final static String CPROFILE_CREATIONDATE = "creationdate";
public final static String CPROFILE_FOS = "fos";
public final static String CPROFILE_SDG = "sdg";
public final static String CPROFILE_ADVANCED_CONSTRAINT = "advancedConstraints";
// community project
public final static String CPROJECT_FUNDER = "funder";
public final static String CPROJECT_NUMBER = "CD_PROJECT_NUMBER";
public final static String CPROJECT_FULLNAME = "projectfullname";
public final static String CPROJECT_ACRONYM = "acronym";
// community content provider
public final static String CCONTENTPROVIDER_NAME = "name";
public final static String CCONTENTPROVIDER_OFFICIALNAME = "officialname";
public final static String CCONTENTPROVIDER_ENABLED = "enabled";
public final static String CCONTENTPROVIDERENABLED_DEFAULT = "true";
public final static String CCONTENTPROVIDER_SELCRITERIA = "selcriteria";
// community zenodo community
public final static String CZENODOCOMMUNITY_ID = "zenodoid";
// community organization
public final static String CORGANIZATION_NAME = "name";
public final static String CORGANIZATION_LOGOURL = "logourl";
public final static String CORGANIZATION_WEBSITEURL = "websiteurl";
}

View File

@ -1,5 +1,9 @@
package eu.dnetlib.openaire.community;
import static eu.dnetlib.openaire.community.CommunityCommon.CONTENTPROVIDERS_ID_SUFFIX;
import static eu.dnetlib.openaire.community.CommunityCommon.ORGANIZATION_ID_SUFFIX;
import static eu.dnetlib.openaire.community.CommunityCommon.PROJECTS_ID_SUFFIX;
import java.util.List;
import java.util.stream.Collectors;
@ -21,11 +25,11 @@ public class CommunityImporterController {
private CommunityService service;
@Autowired
private CommunityApiCore core;
private CommunityCommon cc;
@GetMapping("/community_importer/import")
public List<String> importProfiles() throws CommunityException {
final List<String> list = core.listCommunities()
final List<String> list = cc.listCommunities()
.stream()
.map(c -> c.getId())
.collect(Collectors.toList());
@ -37,10 +41,12 @@ public class CommunityImporterController {
private void importCommunity(final String id) {
try {
final CommunityDetails community = core.getCommunity(id);
final List<CommunityContentprovider> datasources = core.getCommunityContentproviders(id);
final List<CommunityProject> projects = core.getCommunityProjects(id);
final List<CommunityOrganization> orgs = core.getCommunityOrganizations(id);
final CommunityDetails community = cc.getCommunity(id);
final List<CommunityContentprovider> datasources =
cc.getCommunityInfo(id, CONTENTPROVIDERS_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityDataprovider(id, c));
final List<CommunityProject> projects = cc.getCommunityInfo(id, PROJECTS_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityProject(id, c));
final List<CommunityOrganization> orgs = cc.getCommunityInfo(id, ORGANIZATION_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityOrganization(id, c));
service.saveCommunity(community);
service.addCommunityProjectList(id, projects);

View File

@ -1,32 +1,32 @@
package eu.dnetlib.openaire.community;
import static eu.dnetlib.openaire.common.Utils.escape;
import static eu.dnetlib.openaire.community.CommunityConstants.CCONTENTPROVIDER_NAME;
import static eu.dnetlib.openaire.community.CommunityConstants.CCONTENTPROVIDER_OFFICIALNAME;
import static eu.dnetlib.openaire.community.CommunityConstants.CCONTENTPROVIDER_SELCRITERIA;
import static eu.dnetlib.openaire.community.CommunityConstants.CORGANIZATION_LOGOURL;
import static eu.dnetlib.openaire.community.CommunityConstants.CORGANIZATION_NAME;
import static eu.dnetlib.openaire.community.CommunityConstants.CORGANIZATION_WEBSITEURL;
import static eu.dnetlib.openaire.community.CommunityConstants.CPROFILE_ADVANCED_CONSTRAINT;
import static eu.dnetlib.openaire.community.CommunityConstants.CPROFILE_CREATIONDATE;
import static eu.dnetlib.openaire.community.CommunityConstants.CPROFILE_FOS;
import static eu.dnetlib.openaire.community.CommunityConstants.CPROFILE_SDG;
import static eu.dnetlib.openaire.community.CommunityConstants.CPROFILE_SUBJECT;
import static eu.dnetlib.openaire.community.CommunityConstants.CPROJECT_ACRONYM;
import static eu.dnetlib.openaire.community.CommunityConstants.CPROJECT_FULLNAME;
import static eu.dnetlib.openaire.community.CommunityConstants.CPROJECT_FUNDER;
import static eu.dnetlib.openaire.community.CommunityConstants.CPROJECT_NUMBER;
import static eu.dnetlib.openaire.community.CommunityConstants.CSUMMARY_DESCRIPTION;
import static eu.dnetlib.openaire.community.CommunityConstants.CSUMMARY_LOGOURL;
import static eu.dnetlib.openaire.community.CommunityConstants.CSUMMARY_NAME;
import static eu.dnetlib.openaire.community.CommunityConstants.CSUMMARY_STATUS;
import static eu.dnetlib.openaire.community.CommunityConstants.CSUMMARY_ZENODOC;
import static eu.dnetlib.openaire.community.CommunityConstants.CSV_DELIMITER;
import static eu.dnetlib.openaire.community.CommunityConstants.CZENODOCOMMUNITY_ID;
import static eu.dnetlib.openaire.community.CommunityConstants.ID_SEPARATOR;
import static eu.dnetlib.openaire.community.CommunityConstants.OPENAIRE_ID;
import static eu.dnetlib.openaire.community.CommunityConstants.PIPE_SEPARATOR;
import static eu.dnetlib.openaire.community.CommunityConstants.ZENODOCOMMUNITY_ID_SUFFIX;
import static eu.dnetlib.openaire.community.CommunityCommon.CCONTENTPROVIDER_NAME;
import static eu.dnetlib.openaire.community.CommunityCommon.CCONTENTPROVIDER_OFFICIALNAME;
import static eu.dnetlib.openaire.community.CommunityCommon.CCONTENTPROVIDER_SELCRITERIA;
import static eu.dnetlib.openaire.community.CommunityCommon.CORGANIZATION_LOGOURL;
import static eu.dnetlib.openaire.community.CommunityCommon.CORGANIZATION_NAME;
import static eu.dnetlib.openaire.community.CommunityCommon.CORGANIZATION_WEBSITEURL;
import static eu.dnetlib.openaire.community.CommunityCommon.CPROFILE_ADVANCED_CONSTRAINT;
import static eu.dnetlib.openaire.community.CommunityCommon.CPROFILE_CREATIONDATE;
import static eu.dnetlib.openaire.community.CommunityCommon.CPROFILE_FOS;
import static eu.dnetlib.openaire.community.CommunityCommon.CPROFILE_SDG;
import static eu.dnetlib.openaire.community.CommunityCommon.CPROFILE_SUBJECT;
import static eu.dnetlib.openaire.community.CommunityCommon.CPROJECT_ACRONYM;
import static eu.dnetlib.openaire.community.CommunityCommon.CPROJECT_FULLNAME;
import static eu.dnetlib.openaire.community.CommunityCommon.CPROJECT_FUNDER;
import static eu.dnetlib.openaire.community.CommunityCommon.CPROJECT_NUMBER;
import static eu.dnetlib.openaire.community.CommunityCommon.CSUMMARY_DESCRIPTION;
import static eu.dnetlib.openaire.community.CommunityCommon.CSUMMARY_LOGOURL;
import static eu.dnetlib.openaire.community.CommunityCommon.CSUMMARY_NAME;
import static eu.dnetlib.openaire.community.CommunityCommon.CSUMMARY_STATUS;
import static eu.dnetlib.openaire.community.CommunityCommon.CSUMMARY_ZENODOC;
import static eu.dnetlib.openaire.community.CommunityCommon.CSV_DELIMITER;
import static eu.dnetlib.openaire.community.CommunityCommon.CZENODOCOMMUNITY_ID;
import static eu.dnetlib.openaire.community.CommunityCommon.ID_SEPARATOR;
import static eu.dnetlib.openaire.community.CommunityCommon.OPENAIRE_ID;
import static eu.dnetlib.openaire.community.CommunityCommon.PIPE_SEPARATOR;
import static eu.dnetlib.openaire.community.CommunityCommon.ZENODOCOMMUNITY_ID_SUFFIX;
import java.time.LocalDateTime;
import java.time.ZoneId;

View File

@ -43,9 +43,15 @@ import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionC
public class CommunityService {
// TODO
// 1) Subcommunities: importazione tramite profili
// 1) Import tramite profili:
// 1.1) Completare CommunityImporterController
// 1.2) Estrarre dalle classi deprecate (CommunityCommon e CommunityMappingUtils) i metodi necessari all'import
// 1.3) Considerare anche le Subcommunities: importazione tramite profili
// 2) Subcommunities: visualizzazione tramite le context api
// 3) ricontrollare se tutti i campi del database sono esposti dalle api (modello + mapping)
// 3) Implemtare il metodo ConvertionUtils.toCommunity
// 4) Implemtare il metodo CommunityService.setCommunity
// 5) ricontrollare se tutti i campi del database sono esposti dalle api (modello + mapping)
// 6) Verificare Tickets: #8835, #8854, #6483, #3259, #3494
@Autowired
private DbCommunityRepository dbCommunityRepository;
@ -65,7 +71,6 @@ public class CommunityService {
.collect(Collectors.toList());
}
// TODO perche' questo metodo non esisteva prima?
public CommunityDetails saveCommunity(final CommunityDetails details) throws CommunityException {
dbCommunityRepository.save(ConvertionUtils.toCommunity(details));
return getCommunity(details.getId());
@ -181,32 +186,26 @@ public class CommunityService {
return orgList;
}
@Transactional
public CommunityDetails addCommunitySubjects(final String id, final String... subjects) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), false, subjects);
}
@Transactional
public CommunityDetails removeCommunitySubjects(final String id, final String... subjects) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), true, subjects);
}
@Transactional
public CommunityDetails addCommunityFOS(final String id, final String... foss) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), false, foss);
}
@Transactional
public CommunityDetails removeCommunityFOS(final String id, final String... foss) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), true, foss);
}
@Transactional
public CommunityDetails addCommunitySDG(final String id, final String... sdgs) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), false, sdgs);
}
@Transactional
public CommunityDetails removeCommunitySDG(final String id, final String... sdgs) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), true, sdgs);
}
@ -231,7 +230,7 @@ public class CommunityService {
public CommunityDetails removeCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain)
throws CommunityException, ResourceNotFoundException {
if (isMain) {
return updateElementToSimpleField(id, c -> c.getMainZenodoCommunity(), (c, val) -> c.setMainZenodoCommunity(val), null);
return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), null);
} else {
return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), true, zenodoCommunity);
}
@ -240,20 +239,23 @@ public class CommunityService {
public CommunityDetails addCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain)
throws CommunityException, ResourceNotFoundException {
if (isMain) {
return updateElementToSimpleField(id, c -> c.getMainZenodoCommunity(), (c, val) -> c.setMainZenodoCommunity(val), zenodoCommunity);
return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), zenodoCommunity);
} else {
return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), false, zenodoCommunity);
}
}
@Transactional
private CommunityDetails updateElementToSimpleField(final String id,
final Function<DbCommunity, String> getter,
final BiConsumer<DbCommunity, String> setter,
final String value) {
// TODO Auto-generated method stub
return null;
final String value) throws ResourceNotFoundException, CommunityException {
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
setter.accept(dbEntry, value);
dbCommunityRepository.save(dbEntry);
return getCommunity(id);
}
@Transactional
private CommunityDetails modifyElementToArrayField(final String id,
final Function<DbCommunity, String[]> getter,
final BiConsumer<DbCommunity, String[]> setter,

View File

@ -1,7 +1,5 @@
package eu.dnetlib.openaire.community.db.utils;
import static eu.dnetlib.openaire.community.CommunityConstants.PIPE_SEPARATOR;
import java.util.Arrays;
import eu.dnetlib.openaire.community.db.model.DbCommunity;
@ -16,6 +14,8 @@ import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
public class ConvertionUtils {
public final static String PIPE_SEPARATOR = "||";
public static CommunitySummary toCommunitySummary(final DbCommunity c) {
final CommunitySummary summary = new CommunitySummary();
populateSummary(summary, c);