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
15 changed files with 797 additions and 610 deletions
Showing only changes of commit 3edd995e9d - Show all commits

View File

@ -6,6 +6,7 @@ import java.util.Set;
import eu.dnetlib.openaire.exporter.exceptions.CommunityException; import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException; import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
@Deprecated
public interface CommunityClient { public interface CommunityClient {
Map<String, Set<String>> getInverseZenodoCommunityMap() throws CommunityException, ResourceNotFoundException; Map<String, Set<String>> getInverseZenodoCommunityMap() throws CommunityException, ResourceNotFoundException;

View File

@ -1,5 +1,11 @@
package eu.dnetlib.openaire.community; package eu.dnetlib.openaire.community;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -13,9 +19,8 @@ import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
import eu.dnetlib.openaire.exporter.model.community.CommunitySummary; import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
import eu.dnetlib.openaire.exporter.model.community.CommunityZenodoCommunity; import eu.dnetlib.openaire.exporter.model.community.CommunityZenodoCommunity;
import java.util.*;
@Component @Component
@Deprecated
public class CommunityClientImpl implements CommunityClient { public class CommunityClientImpl implements CommunityClient {
private static final Log log = LogFactory.getLog(CommunityClient.class); private static final Log log = LogFactory.getLog(CommunityClient.class);
@ -31,10 +36,10 @@ public class CommunityClientImpl implements CommunityClient {
final List<CommunitySummary> communityList = communityCommon.listCommunities(); final List<CommunitySummary> communityList = communityCommon.listCommunities();
for(CommunitySummary cs :communityList){ for (final CommunitySummary cs : communityList) {
final String communityId = cs.getId(); final String communityId = cs.getId();
List<CommunityZenodoCommunity> czc = communityCommon.getCommunityZenodoCommunities(communityId); final List<CommunityZenodoCommunity> czc = communityCommon.getCommunityZenodoCommunities(communityId);
for(CommunityZenodoCommunity zc:czc){ for (final CommunityZenodoCommunity zc : czc) {
final String zenodoId = zc.getZenodoid(); final String zenodoId = zc.getZenodoid();
if (!inverseListMap.containsKey(zenodoId)) { if (!inverseListMap.containsKey(zenodoId)) {
inverseListMap.put(zc.getZenodoid(), new HashSet<>()); inverseListMap.put(zc.getZenodoid(), new HashSet<>());
@ -51,10 +56,10 @@ public class CommunityClientImpl implements CommunityClient {
return inverseListMap; return inverseListMap;
} }
@Override @Override
@CacheEvict(cacheNames = { "community-cache", "context-cache-community"}, allEntries = true) @CacheEvict(cacheNames = {
"community-cache", "context-cache-community"
}, allEntries = true)
@Scheduled(fixedDelayString = "${openaire.exporter.cache.ttl}") @Scheduled(fixedDelayString = "${openaire.exporter.cache.ttl}")
public void dropCache() { public void dropCache() {
log.debug("dropped community cache"); log.debug("dropped community cache");

View File

@ -1,8 +1,50 @@
package eu.dnetlib.openaire.community; package eu.dnetlib.openaire.community;
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.CONTENTPROVIDERS_ID_SUFFIX;
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_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.ORGANIZATION_ID_SUFFIX;
import static eu.dnetlib.openaire.community.CommunityConstants.PROJECTS_ID_SUFFIX;
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.Base64;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.gson.Gson; import com.google.gson.Gson;
import eu.dnetlib.openaire.common.ISClient; import eu.dnetlib.openaire.common.ISClient;
import eu.dnetlib.openaire.exporter.exceptions.CommunityException; import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException; import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
@ -18,18 +60,8 @@ import eu.dnetlib.openaire.exporter.model.context.Concept;
import eu.dnetlib.openaire.exporter.model.context.Context; import eu.dnetlib.openaire.exporter.model.context.Context;
import eu.dnetlib.openaire.exporter.model.context.Param; import eu.dnetlib.openaire.exporter.model.context.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static eu.dnetlib.openaire.community.CommunityConstants.*;
@Component @Component
@Deprecated
public class CommunityCommon { public class CommunityCommon {
@Autowired @Autowired
@ -38,30 +70,29 @@ public class CommunityCommon {
public Map<String, Context> getContextMap() throws CommunityException { public Map<String, Context> getContextMap() throws CommunityException {
try { try {
return isClient.getCommunityContextMap(); return isClient.getCommunityContextMap();
} catch (IOException e) { } catch (final IOException e) {
throw new CommunityException(e); throw new CommunityException(e);
} }
} }
public List<CommunitySummary> listCommunities() throws CommunityException { public List<CommunitySummary> listCommunities() throws CommunityException {
return getContextMap().values().stream() return getContextMap().values()
.stream()
.filter(context -> !communityBlackList.contains(context.getId())) .filter(context -> !communityBlackList.contains(context.getId()))
.map(CommunityMappingUtils::asCommunitySummary) .map(CommunityMappingUtils::asCommunitySummary)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public <R> List<R> getCommunityInfo(final String id, final String idSuffix, final Function<Concept, R> mapping) throws CommunityException { public <R> List<R> getCommunityInfo(final String id, final String idSuffix, final Function<Concept, R> mapping) throws CommunityException {
final Map<String, Context> contextMap = getContextMap(); final Map<String, Context> contextMap = getContextMap();
final Context context = contextMap.get(id); final Context context = contextMap.get(id);
if (context != null) { if (context != null) {
final Map<String, Category> categories = context.getCategories(); final Map<String, Category> categories = context.getCategories();
final Category category = categories.get(id + idSuffix); final Category category = categories.get(id + idSuffix);
if (category != null) { if (category != null) { return category.getConcepts()
return category.getConcepts().stream() .stream()
.map(mapping) .map(mapping)
.collect(Collectors.toList()); .collect(Collectors.toList()); }
}
} }
return Lists.newArrayList(); return Lists.newArrayList();
} }
@ -80,63 +111,77 @@ public class CommunityCommon {
return getCommunityInfo(id, ZENODOCOMMUNITY_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityZenodoCommunity(id, c)); return getCommunityInfo(id, ZENODOCOMMUNITY_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityZenodoCommunity(id, c));
} }
public void updateProject(final String communityId, final CommunityProject project) throws CommunityException {
public void updateProject(String communityId, CommunityProject project) throws CommunityException {
final Context context = getContextMap().get(communityId); final Context context = getContextMap().get(communityId);
Category prj = context.getCategories().get(communityId + PROJECTS_ID_SUFFIX); final Category prj = context.getCategories().get(communityId + PROJECTS_ID_SUFFIX);
if (prj.getConcepts().stream().map(c -> c.getId()).collect(Collectors.toList()) if (prj.getConcepts()
.stream()
.map(c -> c.getId())
.collect(Collectors.toList())
.contains(communityId + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project.getId())) { .contains(communityId + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project.getId())) {
prj.getConcepts().forEach(concept -> { prj.getConcepts().forEach(concept -> {
if (concept.getId().equals(communityId + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project.getId())) { if (concept.getId().equals(communityId + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project.getId())) {
if (project.getName() != null) { if (project.getName() != null) {
concept.getParams().replace(CPROJECT_FULLNAME, Arrays.asList(new Param() concept.getParams()
.setName(CPROJECT_FULLNAME).setValue(project.getName()))); .replace(CPROJECT_FULLNAME, Arrays.asList(new Param()
.setName(CPROJECT_FULLNAME)
.setValue(project.getName())));
} }
if (project.getAcronym() != null) { if (project.getAcronym() != null) {
if (concept.getParams().keySet().contains(CPROJECT_ACRONYM)) { if (concept.getParams().keySet().contains(CPROJECT_ACRONYM)) {
concept.getParams().replace(CPROJECT_ACRONYM, Arrays.asList(new Param() concept.getParams()
.setName(CPROJECT_ACRONYM).setValue(project.getAcronym()))); .replace(CPROJECT_ACRONYM, Arrays.asList(new Param()
} .setName(CPROJECT_ACRONYM)
else{ .setValue(project.getAcronym())));
concept.getParams().put(CPROJECT_ACRONYM, Arrays.asList(new Param() } else {
.setName(CPROJECT_ACRONYM).setValue(project.getAcronym()))); concept.getParams()
.put(CPROJECT_ACRONYM, Arrays.asList(new Param()
.setName(CPROJECT_ACRONYM)
.setValue(project.getAcronym())));
} }
} }
if (project.getOpenaireId() != null) { if (project.getOpenaireId() != null) {
if (concept.getParams().keySet().contains(OPENAIRE_ID)) { if (concept.getParams().keySet().contains(OPENAIRE_ID)) {
concept.getParams().replace(OPENAIRE_ID, Arrays.asList(new Param() concept.getParams()
.setName(OPENAIRE_ID).setValue(project.getOpenaireId()))); .replace(OPENAIRE_ID, Arrays.asList(new Param()
} .setName(OPENAIRE_ID)
else{ .setValue(project.getOpenaireId())));
concept.getParams().put(OPENAIRE_ID, Arrays.asList(new Param() } else {
.setName(OPENAIRE_ID).setValue(project.getOpenaireId()))); concept.getParams()
.put(OPENAIRE_ID, Arrays.asList(new Param()
.setName(OPENAIRE_ID)
.setValue(project.getOpenaireId())));
} }
} }
if (project.getFunder() != null) { if (project.getFunder() != null) {
concept.getParams().replace(CPROJECT_FUNDER, Arrays.asList(new Param() concept.getParams()
.setName(CPROJECT_FUNDER).setValue(project.getFunder()))); .replace(CPROJECT_FUNDER, Arrays.asList(new Param()
.setName(CPROJECT_FUNDER)
.setValue(project.getFunder())));
} }
if (project.getGrantId() != null) { if (project.getGrantId() != null) {
concept.getParams().replace(CPROJECT_NUMBER, Arrays.asList(new Param() concept.getParams()
.setName(CPROJECT_NUMBER).setValue(project.getGrantId()))); .replace(CPROJECT_NUMBER, Arrays.asList(new Param()
.setName(CPROJECT_NUMBER)
.setValue(project.getGrantId())));
} }
} }
}); });
} } else {
else{ final Concept concept = new Concept();
Concept concept = new Concept();
concept.setId(communityId + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project.getId()); concept.setId(communityId + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project.getId());
concept.setClaim(false); concept.setClaim(false);
if(project.getAcronym() != null) if (project.getAcronym() != null) {
concept.setLabel(project.getAcronym()); concept.setLabel(project.getAcronym());
else } else {
concept.setLabel(""); concept.setLabel("");
}
Map<String, List<Param>> params = new TreeMap<>(); final Map<String, List<Param>> params = new TreeMap<>();
if (project.getAcronym() != null) { if (project.getAcronym() != null) {
params.put(CPROJECT_ACRONYM, Arrays.asList(new Param().setName(CPROJECT_ACRONYM) params.put(CPROJECT_ACRONYM, Arrays.asList(new Param().setName(CPROJECT_ACRONYM)
@ -146,47 +191,43 @@ public class CommunityCommon {
if (project.getName() != null) { if (project.getName() != null) {
params.put(CPROJECT_FULLNAME, Arrays.asList(new Param() params.put(CPROJECT_FULLNAME, Arrays.asList(new Param()
.setName(CPROJECT_FULLNAME) .setName(CPROJECT_FULLNAME)
.setValue(project.getName()) .setValue(project.getName())));
));
} }
if (project.getOpenaireId() != null) { if (project.getOpenaireId() != null) {
params.put(OPENAIRE_ID, Arrays.asList(new Param() params.put(OPENAIRE_ID, Arrays.asList(new Param()
.setName(OPENAIRE_ID) .setName(OPENAIRE_ID)
.setValue(project.getOpenaireId()) .setValue(project.getOpenaireId())));
));
} }
if (project.getFunder() != null) { if (project.getFunder() != null) {
params.put(CPROJECT_FUNDER, Arrays.asList(new Param() params.put(CPROJECT_FUNDER, Arrays.asList(new Param()
.setName(CPROJECT_FUNDER) .setName(CPROJECT_FUNDER)
.setValue(project.getFunder()) .setValue(project.getFunder())));
));
} }
if (project.getGrantId() != null) { if (project.getGrantId() != null) {
params.put(CPROJECT_NUMBER, Arrays.asList(new Param() params.put(CPROJECT_NUMBER, Arrays.asList(new Param()
.setName(CPROJECT_NUMBER) .setName(CPROJECT_NUMBER)
.setValue(project.getGrantId()) .setValue(project.getGrantId())));
));
} }
concept.setParams(params); concept.setParams(params);
prj.getConcepts().add(concept); prj.getConcepts().add(concept);
} }
} }
public void removeAdvancedConstraint(String id) throws CommunityException { public void removeAdvancedConstraint(final String id) throws CommunityException {
final Context context = getContextMap().get(id); final Context context = getContextMap().get(id);
context.getParams() context.getParams()
.replace(CPROFILE_ADVANCED_CONSTRAINT, Arrays.asList(new Param() .replace(CPROFILE_ADVANCED_CONSTRAINT, Arrays.asList(new Param()
.setName(CPROFILE_ADVANCED_CONSTRAINT).setValue(null))); .setName(CPROFILE_ADVANCED_CONSTRAINT)
.setValue(null)));
} }
public void updateCommunity(String id, CommunityWritableProperties community) throws CommunityException { public void updateCommunity(final String id, final CommunityWritableProperties community) throws CommunityException {
final Context context = getContextMap().get(id); final Context context = getContextMap().get(id);
if (community.getShortName() != null) { if (community.getShortName() != null) {
@ -194,24 +235,29 @@ public class CommunityCommon {
} }
if (community.getName() != null) { if (community.getName() != null) {
context.getParams().replace(CSUMMARY_NAME, Arrays.asList(new Param() context.getParams()
.setValue(community.getName()).setName(CSUMMARY_NAME))); .replace(CSUMMARY_NAME, Arrays.asList(new Param()
.setValue(community.getName())
.setName(CSUMMARY_NAME)));
} }
if (community.getDescription() != null) { if (community.getDescription() != null) {
context.getParams() context.getParams()
.replace(CSUMMARY_DESCRIPTION, Arrays.asList(new Param() .replace(CSUMMARY_DESCRIPTION, Arrays.asList(new Param()
.setName(CSUMMARY_DESCRIPTION).setValue(community.getDescription()))); .setName(CSUMMARY_DESCRIPTION)
.setValue(community.getDescription())));
} }
if (community.getLogoUrl() != null) { if (community.getLogoUrl() != null) {
context.getParams() context.getParams()
.replace(CSUMMARY_LOGOURL, Arrays.asList(new Param() .replace(CSUMMARY_LOGOURL, Arrays.asList(new Param()
.setName(CSUMMARY_LOGOURL).setValue(community.getLogoUrl()))); .setName(CSUMMARY_LOGOURL)
.setValue(community.getLogoUrl())));
} }
if (community.getStatus() != null) { if (community.getStatus() != null) {
context.getParams() context.getParams()
.replace(CSUMMARY_STATUS, Arrays.asList(new Param() .replace(CSUMMARY_STATUS, Arrays.asList(new Param()
.setName(CSUMMARY_STATUS).setValue(community.getStatus().name()))); .setName(CSUMMARY_STATUS)
.setValue(community.getStatus().name())));
} }
if (community.getSubjects() != null) { if (community.getSubjects() != null) {
context.getParams() context.getParams()
@ -220,123 +266,146 @@ public class CommunityCommon {
.join(community.getSubjects())))); .join(community.getSubjects()))));
} }
if (community.getFos() != null) { if (community.getFos() != null) {
if (context.getParams().containsKey(CPROFILE_FOS)) if (context.getParams().containsKey(CPROFILE_FOS)) {
context.getParams() context.getParams()
.replace(CPROFILE_FOS, Arrays.asList(new Param().setName(CPROFILE_FOS) .replace(CPROFILE_FOS, Arrays.asList(new Param().setName(CPROFILE_FOS)
.setValue(Joiner.on(CSV_DELIMITER) .setValue(Joiner.on(CSV_DELIMITER)
.join(community.getFos())))); .join(community.getFos()))));
else } else {
context.getParams().put(CPROFILE_FOS, Arrays.asList(new Param().setName(CPROFILE_FOS) context.getParams()
.put(CPROFILE_FOS, Arrays.asList(new Param().setName(CPROFILE_FOS)
.setValue(Joiner.on(CSV_DELIMITER) .setValue(Joiner.on(CSV_DELIMITER)
.join(community.getFos())))); .join(community.getFos()))));
} }
}
if (community.getSdg() != null) { if (community.getSdg() != null) {
if(context.getParams().containsKey(CPROFILE_SDG)) if (context.getParams().containsKey(CPROFILE_SDG)) {
context.getParams() context.getParams()
.replace(CPROFILE_SDG, Arrays.asList(new Param().setName(CPROFILE_SDG) .replace(CPROFILE_SDG, Arrays.asList(new Param().setName(CPROFILE_SDG)
.setValue(Joiner.on(CSV_DELIMITER) .setValue(Joiner.on(CSV_DELIMITER)
.join(community.getSdg())))); .join(community.getSdg()))));
else } else {
context.getParams().put(CPROFILE_SDG, Arrays.asList(new Param().setName(CPROFILE_SDG) context.getParams()
.put(CPROFILE_SDG, Arrays.asList(new Param().setName(CPROFILE_SDG)
.setValue(Joiner.on(CSV_DELIMITER) .setValue(Joiner.on(CSV_DELIMITER)
.join(community.getSdg())))); .join(community.getSdg()))));
} }
}
if (community.getAdvancedConstraints() != null) { if (community.getAdvancedConstraints() != null) {
if(context.getParams().containsKey(CPROFILE_ADVANCED_CONSTRAINT)) if (context.getParams().containsKey(CPROFILE_ADVANCED_CONSTRAINT)) {
context.getParams() context.getParams()
.replace(CPROFILE_ADVANCED_CONSTRAINT, Arrays.asList(new Param() .replace(CPROFILE_ADVANCED_CONSTRAINT, Arrays.asList(new Param()
.setName(CPROFILE_ADVANCED_CONSTRAINT).setValue(new Gson().toJson(community.getAdvancedConstraints())))); .setName(CPROFILE_ADVANCED_CONSTRAINT)
else .setValue(new Gson().toJson(community.getAdvancedConstraints()))));
context.getParams().put(CPROFILE_ADVANCED_CONSTRAINT, Arrays.asList(new Param() } else {
.setName(CPROFILE_ADVANCED_CONSTRAINT).setValue(new Gson().toJson(community.getAdvancedConstraints())))); context.getParams()
.put(CPROFILE_ADVANCED_CONSTRAINT, Arrays.asList(new Param()
.setName(CPROFILE_ADVANCED_CONSTRAINT)
.setValue(new Gson().toJson(community.getAdvancedConstraints()))));
}
} }
if (community.getMainZenodoCommunity() != null) { if (community.getMainZenodoCommunity() != null) {
context.getParams() context.getParams()
.replace(CSUMMARY_ZENODOC, Arrays.asList(new Param() .replace(CSUMMARY_ZENODOC, Arrays.asList(new Param()
.setName(CSUMMARY_ZENODOC).setValue(community.getMainZenodoCommunity()))); .setName(CSUMMARY_ZENODOC)
.setValue(community.getMainZenodoCommunity())));
} }
} }
public void removeFromCategory(final String communityId, final String category, final String conceptId) throws CommunityException {
final Map<String, Context> cmap = getContextMap();
final Context context = cmap.get(communityId);
final Map<String, Category> cat = context.getCategories();
public void removeFromCategory(String communityId, String category, String conceptId) throws CommunityException { final List<Concept> concepts = cat.get(communityId + category)
Map<String, Context> cmap = getContextMap(); .getConcepts()
Context context = cmap.get(communityId); .stream()
Map<String, Category> cat = context.getCategories(); .filter(c -> !c.getId().equals(communityId + category + ID_SEPARATOR + conceptId))
.collect(Collectors.toList());
List<Concept> concepts = cat.get(communityId + category).getConcepts()
.stream().filter(c -> !c.getId().equals(communityId + category + ID_SEPARATOR + conceptId)).collect(Collectors.toList());
cat.get(communityId + category).setConcepts(concepts); cat.get(communityId + category).setConcepts(concepts);
} }
public void updateDatasource(String communityId, CommunityContentprovider cp) throws CommunityException { public void updateDatasource(final String communityId, final CommunityContentprovider cp) throws CommunityException {
final Context context = getContextMap().get(communityId); final Context context = getContextMap().get(communityId);
Category dts = context.getCategories().get(communityId + CONTENTPROVIDERS_ID_SUFFIX); final Category dts = context.getCategories().get(communityId + CONTENTPROVIDERS_ID_SUFFIX);
if (dts.getConcepts().stream().map(c -> c.getId()).collect(Collectors.toList()) if (dts.getConcepts()
.stream()
.map(c -> c.getId())
.collect(Collectors.toList())
.contains(communityId + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + cp.getId())) { .contains(communityId + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + cp.getId())) {
dts.getConcepts().forEach(concept -> { dts.getConcepts().forEach(concept -> {
if (concept.getId().equals(communityId + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + cp.getId())) { if (concept.getId().equals(communityId + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + cp.getId())) {
if (cp.getName() != null) { if (cp.getName() != null) {
if (concept.getParams().keySet().contains(CCONTENTPROVIDER_NAME)) { if (concept.getParams().keySet().contains(CCONTENTPROVIDER_NAME)) {
concept.getParams().replace(CCONTENTPROVIDER_NAME, Arrays.asList(new Param() concept.getParams()
.setName(CCONTENTPROVIDER_NAME).setValue(cp.getName()))); .replace(CCONTENTPROVIDER_NAME, Arrays.asList(new Param()
} .setName(CCONTENTPROVIDER_NAME)
else{ .setValue(cp.getName())));
concept.getParams().put(CCONTENTPROVIDER_NAME, Arrays.asList(new Param() } else {
.setName(CCONTENTPROVIDER_NAME).setValue(cp.getName()))); concept.getParams()
.put(CCONTENTPROVIDER_NAME, Arrays.asList(new Param()
.setName(CCONTENTPROVIDER_NAME)
.setValue(cp.getName())));
} }
} }
if (cp.getOfficialname() != null) { if (cp.getOfficialname() != null) {
if (concept.getParams().keySet().contains(CCONTENTPROVIDER_OFFICIALNAME)) { if (concept.getParams().keySet().contains(CCONTENTPROVIDER_OFFICIALNAME)) {
concept.getParams().replace(CCONTENTPROVIDER_OFFICIALNAME, Arrays.asList(new Param() concept.getParams()
.setName(CCONTENTPROVIDER_OFFICIALNAME).setValue(cp.getOfficialname()))); .replace(CCONTENTPROVIDER_OFFICIALNAME, Arrays.asList(new Param()
} .setName(CCONTENTPROVIDER_OFFICIALNAME)
else{ .setValue(cp.getOfficialname())));
concept.getParams().put(CCONTENTPROVIDER_OFFICIALNAME, Arrays.asList(new Param() } else {
.setName(CCONTENTPROVIDER_OFFICIALNAME).setValue(cp.getOfficialname()))); concept.getParams()
.put(CCONTENTPROVIDER_OFFICIALNAME, Arrays.asList(new Param()
.setName(CCONTENTPROVIDER_OFFICIALNAME)
.setValue(cp.getOfficialname())));
} }
} }
if (cp.getOpenaireId() != null) { if (cp.getOpenaireId() != null) {
if (concept.getParams().keySet().contains(OPENAIRE_ID)) { if (concept.getParams().keySet().contains(OPENAIRE_ID)) {
concept.getParams().replace(OPENAIRE_ID, Arrays.asList(new Param() concept.getParams()
.setName(OPENAIRE_ID).setValue(cp.getOpenaireId()))); .replace(OPENAIRE_ID, Arrays.asList(new Param()
} .setName(OPENAIRE_ID)
else{ .setValue(cp.getOpenaireId())));
concept.getParams().put(OPENAIRE_ID, Arrays.asList(new Param() } else {
.setName(OPENAIRE_ID).setValue(cp.getOpenaireId()))); concept.getParams()
.put(OPENAIRE_ID, Arrays.asList(new Param()
.setName(OPENAIRE_ID)
.setValue(cp.getOpenaireId())));
} }
} }
if (cp.getSelectioncriteria() != null) { if (cp.getSelectioncriteria() != null) {
if (concept.getParams().keySet().contains(CCONTENTPROVIDER_SELCRITERIA)) { if (concept.getParams().keySet().contains(CCONTENTPROVIDER_SELCRITERIA)) {
concept.getParams().replace(CCONTENTPROVIDER_SELCRITERIA, Arrays.asList(new Param() concept.getParams()
.setName(CCONTENTPROVIDER_SELCRITERIA).setValue(cp.toJson()))); .replace(CCONTENTPROVIDER_SELCRITERIA, Arrays.asList(new Param()
} .setName(CCONTENTPROVIDER_SELCRITERIA)
else{ .setValue(cp.toJson())));
concept.getParams().put(CCONTENTPROVIDER_SELCRITERIA, Arrays.asList(new Param() } else {
.setName(CCONTENTPROVIDER_SELCRITERIA).setValue(cp.toJson()))); concept.getParams()
.put(CCONTENTPROVIDER_SELCRITERIA, Arrays.asList(new Param()
.setName(CCONTENTPROVIDER_SELCRITERIA)
.setValue(cp.toJson())));
} }
} }
} }
}); });
} } else {
else{ final Concept concept = new Concept();
Concept concept = new Concept();
concept.setId(communityId + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + cp.getId()); concept.setId(communityId + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + cp.getId());
concept.setClaim(false); concept.setClaim(false);
concept.setLabel(""); concept.setLabel("");
Map<String, List<Param>> params = new TreeMap<>(); final Map<String, List<Param>> params = new TreeMap<>();
if (cp.getName() != null) { if (cp.getName() != null) {
params.put(CCONTENTPROVIDER_NAME, Arrays.asList(new Param().setValue(cp.getName()).setName(CCONTENTPROVIDER_NAME))); params.put(CCONTENTPROVIDER_NAME, Arrays.asList(new Param().setValue(cp.getName()).setName(CCONTENTPROVIDER_NAME)));
@ -355,53 +424,62 @@ public class CommunityCommon {
concept.setParams(params); concept.setParams(params);
dts.getConcepts().add(concept); dts.getConcepts().add(concept);
} }
} }
public void updateOrganization(String communityId, CommunityOrganization organization) throws CommunityException { public void updateOrganization(final String communityId, final CommunityOrganization organization) throws CommunityException {
final Context context = getContextMap().get(communityId); final Context context = getContextMap().get(communityId);
Category orgs = context.getCategories().get(communityId + ORGANIZATION_ID_SUFFIX); final Category orgs = context.getCategories().get(communityId + ORGANIZATION_ID_SUFFIX);
if (orgs.getConcepts().stream().map(c -> c.getId()).collect(Collectors.toList()) if (orgs.getConcepts()
.stream()
.map(c -> c.getId())
.collect(Collectors.toList())
.contains(communityId + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organization.getId())) { .contains(communityId + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organization.getId())) {
orgs.getConcepts().forEach(concept -> { orgs.getConcepts().forEach(concept -> {
if (concept.getId().equals(communityId + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organization.getId())) { if (concept.getId().equals(communityId + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organization.getId())) {
if (organization.getName() != null) { if (organization.getName() != null) {
if (concept.getParams().keySet().contains(CORGANIZATION_NAME)) { if (concept.getParams().keySet().contains(CORGANIZATION_NAME)) {
concept.getParams().replace(CORGANIZATION_NAME, Arrays.asList(new Param() concept.getParams()
.setName(CORGANIZATION_NAME).setValue(organization.getName()))); .replace(CORGANIZATION_NAME, Arrays.asList(new Param()
} .setName(CORGANIZATION_NAME)
else{ .setValue(organization.getName())));
concept.getParams().put(CORGANIZATION_NAME, Arrays.asList(new Param() } else {
.setName(CORGANIZATION_NAME).setValue(organization.getName()))); concept.getParams()
.put(CORGANIZATION_NAME, Arrays.asList(new Param()
.setName(CORGANIZATION_NAME)
.setValue(organization.getName())));
} }
} }
if (organization.getLogo_url() != null) { if (organization.getLogo_url() != null) {
if (concept.getParams().keySet().contains(CORGANIZATION_LOGOURL)) { if (concept.getParams().keySet().contains(CORGANIZATION_LOGOURL)) {
concept.getParams().replace(CORGANIZATION_LOGOURL, Arrays.asList(new Param() concept.getParams()
.setName(CORGANIZATION_LOGOURL).setValue(Base64.getEncoder().encodeToString(organization.getLogo_url().getBytes())))); .replace(CORGANIZATION_LOGOURL, Arrays.asList(new Param()
} .setName(CORGANIZATION_LOGOURL)
else{ .setValue(Base64.getEncoder().encodeToString(organization.getLogo_url().getBytes()))));
concept.getParams().put(CORGANIZATION_LOGOURL, Arrays.asList(new Param() } else {
.setName(CORGANIZATION_LOGOURL).setValue(Base64.getEncoder().encodeToString(organization.getLogo_url().getBytes())))); concept.getParams()
.put(CORGANIZATION_LOGOURL, Arrays.asList(new Param()
.setName(CORGANIZATION_LOGOURL)
.setValue(Base64.getEncoder().encodeToString(organization.getLogo_url().getBytes()))));
} }
} }
if (organization.getWebsite_url() != null) { if (organization.getWebsite_url() != null) {
if (concept.getParams().keySet().contains(CORGANIZATION_WEBSITEURL)) { if (concept.getParams().keySet().contains(CORGANIZATION_WEBSITEURL)) {
concept.getParams().replace(CORGANIZATION_WEBSITEURL, Arrays.asList(new Param() concept.getParams()
.setName(CORGANIZATION_WEBSITEURL).setValue(Base64.getEncoder().encodeToString(organization.getWebsite_url().getBytes())))); .replace(CORGANIZATION_WEBSITEURL, Arrays.asList(new Param()
} .setName(CORGANIZATION_WEBSITEURL)
else{ .setValue(Base64.getEncoder().encodeToString(organization.getWebsite_url().getBytes()))));
concept.getParams().put(CORGANIZATION_WEBSITEURL, Arrays.asList(new Param() } else {
.setName(CORGANIZATION_WEBSITEURL).setValue(Base64.getEncoder().encodeToString(organization.getWebsite_url().getBytes())))); concept.getParams()
.put(CORGANIZATION_WEBSITEURL, Arrays.asList(new Param()
.setName(CORGANIZATION_WEBSITEURL)
.setValue(Base64.getEncoder().encodeToString(organization.getWebsite_url().getBytes()))));
} }
} }
@ -409,53 +487,58 @@ public class CommunityCommon {
} }
}); });
} } else {
else{
Concept concept = new Concept(); final Concept concept = new Concept();
concept.setId(communityId + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organization.getId()); concept.setId(communityId + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organization.getId());
concept.setClaim(false); concept.setClaim(false);
concept.setLabel(""); concept.setLabel("");
Map<String, List<Param>> params = new TreeMap<>(); final Map<String, List<Param>> params = new TreeMap<>();
if (organization.getName() != null) { if (organization.getName() != null) {
params.put(CORGANIZATION_NAME, Arrays.asList(new Param().setValue(organization.getName()).setName(CORGANIZATION_NAME))); params.put(CORGANIZATION_NAME, Arrays.asList(new Param().setValue(organization.getName()).setName(CORGANIZATION_NAME)));
} }
if (organization.getLogo_url() != null) { if (organization.getLogo_url() != null) {
params.put( CORGANIZATION_LOGOURL, Arrays.asList(new Param().setValue(Base64.getEncoder().encodeToString(organization.getLogo_url().getBytes())).setName(CORGANIZATION_LOGOURL))); params.put(CORGANIZATION_LOGOURL, Arrays
.asList(new Param().setValue(Base64.getEncoder().encodeToString(organization.getLogo_url().getBytes())).setName(CORGANIZATION_LOGOURL)));
} }
if (organization.getWebsite_url() != null) { if (organization.getWebsite_url() != null) {
params.put( CORGANIZATION_WEBSITEURL, Arrays.asList(new Param().setValue(Base64.getEncoder().encodeToString(organization.getWebsite_url().getBytes())).setName(CORGANIZATION_WEBSITEURL))); params.put(CORGANIZATION_WEBSITEURL, Arrays
.asList(new Param().setValue(Base64.getEncoder().encodeToString(organization.getWebsite_url().getBytes()))
.setName(CORGANIZATION_WEBSITEURL)));
} }
concept.setParams(params); concept.setParams(params);
orgs.getConcepts().add(concept); orgs.getConcepts().add(concept);
} }
} }
public void updateZenodoCommunity(String communityId, CommunityZenodoCommunity zc) throws CommunityException { public void updateZenodoCommunity(final String communityId, final CommunityZenodoCommunity zc) throws CommunityException {
final Context context = getContextMap().get(communityId); final Context context = getContextMap().get(communityId);
Category zcs = context.getCategories().get(communityId + ZENODOCOMMUNITY_ID_SUFFIX); final Category zcs = context.getCategories().get(communityId + ZENODOCOMMUNITY_ID_SUFFIX);
if (zcs.getConcepts().stream().map(c -> c.getId()).collect(Collectors.toList()) if (zcs.getConcepts()
.stream()
.map(c -> c.getId())
.collect(Collectors.toList())
.contains(communityId + ZENODOCOMMUNITY_ID_SUFFIX + ID_SEPARATOR + zc.getId())) { .contains(communityId + ZENODOCOMMUNITY_ID_SUFFIX + ID_SEPARATOR + zc.getId())) {
zcs.getConcepts().forEach(concept -> { zcs.getConcepts().forEach(concept -> {
if (concept.getId().equals(communityId + ZENODOCOMMUNITY_ID_SUFFIX + ID_SEPARATOR + zc.getId())) { if (concept.getId().equals(communityId + ZENODOCOMMUNITY_ID_SUFFIX + ID_SEPARATOR + zc.getId())) {
if (zc.getZenodoid() != null) { if (zc.getZenodoid() != null) {
if (concept.getParams().keySet().contains(CZENODOCOMMUNITY_ID)) { if (concept.getParams().keySet().contains(CZENODOCOMMUNITY_ID)) {
concept.getParams().replace(CZENODOCOMMUNITY_ID, Arrays.asList(new Param() concept.getParams()
.setName(CZENODOCOMMUNITY_ID).setValue(zc.getZenodoid()))); .replace(CZENODOCOMMUNITY_ID, Arrays.asList(new Param()
} .setName(CZENODOCOMMUNITY_ID)
else{ .setValue(zc.getZenodoid())));
concept.getParams().put(CZENODOCOMMUNITY_ID, Arrays.asList(new Param() } else {
.setName(CZENODOCOMMUNITY_ID).setValue(zc.getZenodoid()))); concept.getParams()
.put(CZENODOCOMMUNITY_ID, Arrays.asList(new Param()
.setName(CZENODOCOMMUNITY_ID)
.setValue(zc.getZenodoid())));
} }
} }
@ -463,15 +546,13 @@ public class CommunityCommon {
} }
}); });
} } else {
else{
Concept concept = new Concept(); final Concept concept = new Concept();
concept.setId(communityId + ZENODOCOMMUNITY_ID_SUFFIX + ID_SEPARATOR + zc.getId()); concept.setId(communityId + ZENODOCOMMUNITY_ID_SUFFIX + ID_SEPARATOR + zc.getId());
concept.setClaim(false); concept.setClaim(false);
final Map<String, List<Param>> params = new TreeMap<>();
Map<String, List<Param>> params = new TreeMap<>();
if (zc.getZenodoid() != null) { if (zc.getZenodoid() != null) {
params.put(CZENODOCOMMUNITY_ID, Arrays.asList(new Param().setValue(zc.getZenodoid()).setName(CZENODOCOMMUNITY_ID))); params.put(CZENODOCOMMUNITY_ID, Arrays.asList(new Param().setValue(zc.getZenodoid()).setName(CZENODOCOMMUNITY_ID)));

View File

@ -4,6 +4,7 @@ import java.util.Set;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@Deprecated
public class CommunityConstants { public class CommunityConstants {
public final static Set<String> communityBlackList = Sets.newHashSet("fet-fp7", "fet-h2020"); public final static Set<String> communityBlackList = Sets.newHashSet("fet-fp7", "fet-h2020");
@ -57,5 +58,4 @@ public class CommunityConstants {
public final static String CORGANIZATION_LOGOURL = "logourl"; public final static String CORGANIZATION_LOGOURL = "logourl";
public final static String CORGANIZATION_WEBSITEURL = "websiteurl"; public final static String CORGANIZATION_WEBSITEURL = "websiteurl";
} }

View File

@ -1,10 +1,50 @@
package eu.dnetlib.openaire.community; package eu.dnetlib.openaire.community;
import static eu.dnetlib.openaire.common.Utils.escape;
import static eu.dnetlib.openaire.community.CommunityConstants.CCONTENTPROVIDERENABLED_DEFAULT;
import static eu.dnetlib.openaire.community.CommunityConstants.CCONTENTPROVIDER_ENABLED;
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.CONTENTPROVIDERS_ID_SUFFIX;
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.ORGANIZATION_ID_SUFFIX;
import static eu.dnetlib.openaire.community.CommunityConstants.PIPE_SEPARATOR;
import static eu.dnetlib.openaire.community.CommunityConstants.PROJECTS_ID_SUFFIX;
import static eu.dnetlib.openaire.community.CommunityConstants.ZENODOCOMMUNITY_ID_SUFFIX;
import java.text.ParseException; import java.text.ParseException;
import java.util.*; import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.google.common.escape.Escaper; import com.google.common.escape.Escaper;
import com.google.common.xml.XmlEscapers; import com.google.common.xml.XmlEscapers;
@ -20,13 +60,7 @@ import eu.dnetlib.openaire.exporter.model.context.Concept;
import eu.dnetlib.openaire.exporter.model.context.Context; import eu.dnetlib.openaire.exporter.model.context.Context;
import eu.dnetlib.openaire.exporter.model.context.Param; import eu.dnetlib.openaire.exporter.model.context.Param;
import org.apache.commons.lang3.StringUtils; @Deprecated
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import static eu.dnetlib.openaire.common.Utils.escape;
import static eu.dnetlib.openaire.community.CommunityConstants.*;
public class CommunityMappingUtils { public class CommunityMappingUtils {
private final static String pattern = "yyyy-MM-dd'T'hh:mm:ss"; private final static String pattern = "yyyy-MM-dd'T'hh:mm:ss";
@ -38,8 +72,8 @@ public class CommunityMappingUtils {
summary.setId(c.getId()); summary.setId(c.getId());
summary.setShortName(c.getLabel()); summary.setShortName(c.getLabel());
summary.setLastUpdateDate(c.getLastUpdateDate()); // summary.setLastUpdateDate(c.getLastUpdateDate());
summary.setCreationDate(c.getCreationDate()); // summary.setCreationDate(c.getCreationDate());
summary.setQueryId(c.getId() + PIPE_SEPARATOR + c.getLabel()); summary.setQueryId(c.getId() + PIPE_SEPARATOR + c.getLabel());
summary.setType(c.getType()); summary.setType(c.getType());
@ -85,7 +119,7 @@ public class CommunityMappingUtils {
if (params.containsKey(CPROFILE_CREATIONDATE)) { if (params.containsKey(CPROFILE_CREATIONDATE)) {
try { try {
p.setCreationDate(org.apache.commons.lang3.time.DateUtils.parseDate(asCsv(params.get(CPROFILE_CREATIONDATE)), pattern)); p.setCreationDate(org.apache.commons.lang3.time.DateUtils.parseDate(asCsv(params.get(CPROFILE_CREATIONDATE)), pattern));
}catch(ParseException e) { } catch (final ParseException e) {
log.debug("Exception on date format: " + e.getMessage()); log.debug("Exception on date format: " + e.getMessage());
} }
} }
@ -131,8 +165,7 @@ public class CommunityMappingUtils {
return z; return z;
} }
public static CommunityOrganization asCommunityOrganization(final String id, final Concept c) {
public static CommunityOrganization asCommunityOrganization(String id, Concept c) {
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);
@ -145,13 +178,10 @@ public class CommunityMappingUtils {
} }
private static String getDecodedUrl(final String encoded_url) { private static String getDecodedUrl(final String encoded_url) {
if(encoded_url == null){ if (encoded_url == null) { return encoded_url; }
return encoded_url;
}
return new String(Base64.getDecoder().decode(encoded_url)); return new String(Base64.getDecoder().decode(encoded_url));
} }
private static List<String> splitValues(final Stream<String> stream, final String separator) { private static List<String> splitValues(final Stream<String> stream, final String separator) {
return stream.map(s -> s.split(separator)) return stream.map(s -> s.split(separator))
.map(Arrays::asList) .map(Arrays::asList)
@ -171,7 +201,8 @@ public class CommunityMappingUtils {
} }
private static Stream<String> asValues(final List<Param> params) { private static Stream<String> asValues(final List<Param> params) {
return params == null ? Stream.empty() : params.stream() return params == null ? Stream.empty()
: params.stream()
.map(Param::getValue) .map(Param::getValue)
.map(StringUtils::trim) .map(StringUtils::trim)
.distinct(); .distinct();
@ -180,10 +211,9 @@ public class CommunityMappingUtils {
public static String asProjectXML(final String contextId, final CommunityProject project) { public static String asProjectXML(final String contextId, final CommunityProject project) {
final Escaper esc = XmlEscapers.xmlAttributeEscaper(); final Escaper esc = XmlEscapers.xmlAttributeEscaper();
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append( sb.append(String
String.format( .format("<concept claim='false' id='%s%s%s%s' label='%s'>\n", escape(esc, contextId), PROJECTS_ID_SUFFIX, ID_SEPARATOR, escape(esc, String
"<concept claim='false' id='%s%s%s%s' label='%s'>\n", .valueOf(project.getId())), escape(esc, project.getAcronym())));
escape(esc, contextId), PROJECTS_ID_SUFFIX, ID_SEPARATOR, escape(esc, String.valueOf(project.getId())), escape(esc, project.getAcronym())));
sb.append(paramXML(CPROJECT_FULLNAME, project.getName())); sb.append(paramXML(CPROJECT_FULLNAME, project.getName()));
sb.append(paramXML(CPROJECT_ACRONYM, project.getAcronym())); sb.append(paramXML(CPROJECT_ACRONYM, project.getAcronym()));
sb.append(paramXML(CPROJECT_NUMBER, project.getGrantId())); sb.append(paramXML(CPROJECT_NUMBER, project.getGrantId()));
@ -197,10 +227,9 @@ public class CommunityMappingUtils {
log.info("creating the XML for the content provider"); log.info("creating the XML for the content provider");
final Escaper esc = XmlEscapers.xmlAttributeEscaper(); final Escaper esc = XmlEscapers.xmlAttributeEscaper();
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append( sb.append(String
String.format( .format("<concept claim='false' id='%s%s%s%s' label='%s'>\n", escape(esc, contextId), CONTENTPROVIDERS_ID_SUFFIX, ID_SEPARATOR, escape(esc, String
"<concept claim='false' id='%s%s%s%s' label='%s'>\n", .valueOf(ccp.getId())), escape(esc, ccp.getName())));
escape(esc, contextId), CONTENTPROVIDERS_ID_SUFFIX, ID_SEPARATOR, escape(esc, String.valueOf(ccp.getId())), escape(esc, ccp.getName())));
sb.append(paramXML(OPENAIRE_ID, ccp.getOpenaireId())); sb.append(paramXML(OPENAIRE_ID, ccp.getOpenaireId()));
sb.append(paramXML(CCONTENTPROVIDER_NAME, ccp.getName())); sb.append(paramXML(CCONTENTPROVIDER_NAME, ccp.getName()));
sb.append(paramXML(CCONTENTPROVIDER_OFFICIALNAME, ccp.getOfficialname())); sb.append(paramXML(CCONTENTPROVIDER_OFFICIALNAME, ccp.getOfficialname()));
@ -214,24 +243,21 @@ public class CommunityMappingUtils {
public static String asZenodoCommunityXML(final String contextId, final CommunityZenodoCommunity zc) { public static String asZenodoCommunityXML(final String contextId, final CommunityZenodoCommunity zc) {
final Escaper esc = XmlEscapers.xmlAttributeEscaper(); final Escaper esc = XmlEscapers.xmlAttributeEscaper();
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append( sb.append(String
String.format( .format("<concept claim='false' id='%s%s%s%s' label='%s'>\n", escape(esc, contextId), ZENODOCOMMUNITY_ID_SUFFIX, ID_SEPARATOR, escape(esc, String
"<concept claim='false' id='%s%s%s%s' label='%s'>\n", .valueOf(zc.getId())), escape(esc, zc.getZenodoid())));
escape(esc, contextId), ZENODOCOMMUNITY_ID_SUFFIX, ID_SEPARATOR, escape(esc, String.valueOf(zc.getId())), escape(esc, zc.getZenodoid())));
sb.append(paramXML(CZENODOCOMMUNITY_ID, zc.getZenodoid())); sb.append(paramXML(CZENODOCOMMUNITY_ID, zc.getZenodoid()));
sb.append("</concept>\n"); sb.append("</concept>\n");
return sb.toString(); return sb.toString();
} }
public static String asOrganizationXML(final String contextId, final CommunityOrganization organization) {
public static String asOrganizationXML(final String contextId, CommunityOrganization organization) {
final Escaper esc = XmlEscapers.xmlAttributeEscaper(); final Escaper esc = XmlEscapers.xmlAttributeEscaper();
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append( sb.append(String
String.format( .format("<concept claim='false' id='%s%s%s%s' label='%s'>\n", escape(esc, contextId), ORGANIZATION_ID_SUFFIX, ID_SEPARATOR, escape(esc, String
"<concept claim='false' id='%s%s%s%s' label='%s'>\n", .valueOf(organization.getId())), escape(esc, organization.getName())));
escape(esc, contextId), ORGANIZATION_ID_SUFFIX, ID_SEPARATOR, escape(esc, String.valueOf(organization.getId())), escape(esc, organization.getName())));
sb.append(paramXML(CORGANIZATION_NAME, organization.getName())); sb.append(paramXML(CORGANIZATION_NAME, organization.getName()));
sb.append(paramXML(CORGANIZATION_LOGOURL, Base64.getEncoder().encodeToString(organization.getLogo_url().getBytes()))); sb.append(paramXML(CORGANIZATION_LOGOURL, Base64.getEncoder().encodeToString(organization.getLogo_url().getBytes())));
sb.append(paramXML(CORGANIZATION_WEBSITEURL, Base64.getEncoder().encodeToString(organization.getWebsite_url().getBytes()))); sb.append(paramXML(CORGANIZATION_WEBSITEURL, Base64.getEncoder().encodeToString(organization.getWebsite_url().getBytes())));
@ -239,7 +265,6 @@ public class CommunityMappingUtils {
return sb.toString(); return sb.toString();
} }
private static String paramXML(final String paramName, final String value) { private static String paramXML(final String paramName, final String value) {
return String.format("<param name='%s'>%s</param>\n", paramName, escape(XmlEscapers.xmlContentEscaper(), value)); return String.format("<param name='%s'>%s</param>\n", paramName, escape(XmlEscapers.xmlContentEscaper(), value));
} }

View File

@ -51,6 +51,11 @@ public class CommunityService {
// 5) Capire come gestire il campo Id (Integer) di CommunityContentprovider // 5) Capire come gestire il campo Id (Integer) di CommunityContentprovider
// 6) Capire come gestire il campo Id (Integer) di CommunityOrganization // 6) Capire come gestire il campo Id (Integer) di CommunityOrganization
// 7) Modificare le api per gestire le ZenodoCommunities (main + others) // 7) Modificare le api per gestire le ZenodoCommunities (main + others)
// 8) i campi name e lastUpdate mancano nel nuovo modello delle communities, si aggiungono?
// 9) i campi officialName e selectioncriteria mancano nel nuovo modello delle datasource, si aggiungono?
// 10) i campi name, logoUrl e websiteUrl mancano nel nuovo modello delle organization,
// esistono solo in quello delle support_org, occorre rivedere le api e i mapping
// 11) Move enums in dnet-exporter-model
@Autowired @Autowired
private DbCommunityRepository dbCommunityRepository; private DbCommunityRepository dbCommunityRepository;

View File

@ -1,5 +1,7 @@
package eu.dnetlib.openaire.community.db; package eu.dnetlib.openaire.community.db;
import static eu.dnetlib.openaire.community.CommunityConstants.PIPE_SEPARATOR;
import eu.dnetlib.openaire.community.db.model.DbCommunity; import eu.dnetlib.openaire.community.db.model.DbCommunity;
import eu.dnetlib.openaire.community.db.model.DbDatasource; import eu.dnetlib.openaire.community.db.model.DbDatasource;
import eu.dnetlib.openaire.community.db.model.DbOrganization; import eu.dnetlib.openaire.community.db.model.DbOrganization;
@ -11,14 +13,40 @@ import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
public class ConvertionUtils { public class ConvertionUtils {
public static CommunitySummary toSummary(final DbCommunity dbEntry) { public static CommunitySummary toSummary(final DbCommunity c) {
// TODO final CommunitySummary summary = new CommunitySummary();
return null;
summary.setId(c.getId());
summary.setShortName(c.getLabel());
summary.setName(null); // TODO: the field is missing in the db model
summary.setLastUpdateDate(null); // TODO: the field is missing in the db model
summary.setCreationDate(c.getCreationDate());
summary.setQueryId(c.getId() + PIPE_SEPARATOR + c.getLabel());
summary.setType(c.getType().toString());
summary.setDescription(c.getDescription());
summary.setLogoUrl(c.getLogoUrl());
summary.setStatus(c.getStatus());
summary.setZenodoCommunity(c.getMainZenodoCommunity());
return summary;
} }
public static CommunityProject toCommunityProject(final DbProject dbEntry) { public static CommunityProject toCommunityProject(final DbProject dbEntry) {
// TODO final CommunityProject cp = new CommunityProject();
return null;
cp.setCommunityId(dbEntry.getCommunity());
// TODO id e openaireId sono uguali
cp.setId(dbEntry.getProjectId());
cp.setOpenaireId(dbEntry.getProjectId());
cp.setName(dbEntry.getProjectName());
cp.setAcronym(dbEntry.getProjectAcronym());
cp.setFunder(dbEntry.getProjectFunder());
cp.setGrantId(dbEntry.getProjectCode());
return cp;
} }
public static DbProject toDbProject(final String id, final CommunityProject project) { public static DbProject toDbProject(final String id, final CommunityProject project) {
@ -27,8 +55,22 @@ public class ConvertionUtils {
} }
public static CommunityContentprovider toCommunityContentprovider(final DbDatasource dbEntry) { public static CommunityContentprovider toCommunityContentprovider(final DbDatasource dbEntry) {
// TODO final CommunityContentprovider ccp = new CommunityContentprovider();
return null;
ccp.setCommunityId(dbEntry.getCommunity());
// TODO id e openaireId sono uguali
ccp.setId(dbEntry.getDsId());
ccp.setOpenaireId(dbEntry.getDsId());
// TODO name e officialName sono uguali
ccp.setName(dbEntry.getDsName());
ccp.setOfficialname(dbEntry.getDsName());
// TODO il campo manca nel nuovo modello
ccp.setSelectioncriteria(null);
return ccp;
} }
public static DbDatasource toDbDatasource(final String id, final CommunityContentprovider provider) { public static DbDatasource toDbDatasource(final String id, final CommunityContentprovider provider) {
@ -37,8 +79,18 @@ public class ConvertionUtils {
} }
public static CommunityOrganization toCommunityOrganiztion(final DbOrganization dbEntry) { public static CommunityOrganization toCommunityOrganiztion(final DbOrganization dbEntry) {
// TODO final CommunityOrganization co = new CommunityOrganization();
return null; co.setCommunityId(dbEntry.getCommunity());
co.setId(dbEntry.getOrgId());
// TODO:
// queste informazioni sono mancanti nel modello delle organizations
// ma esitono in quello delle support_organizations
co.setLogo_url(null);
co.setName(null);
co.setWebsite_url(null);
return co;
} }
public static DbOrganization toDbOrganization(final String id, final CommunityOrganization org) { public static DbOrganization toDbOrganization(final String id, final CommunityOrganization org) {

View File

@ -1,7 +1,26 @@
package eu.dnetlib.openaire.community.db.enums; package eu.dnetlib.openaire.community.db.enums;
public enum CommunityClaimType { public enum CommunityClaimType {
managersOnly,
membersOnly, managersOnly("managers-only"),
all membersOnly("members-only"),
all("all");
private final String description;
private CommunityClaimType(final String description) {
this.description = description;
}
public String getDescription() {
return description;
}
public static CommunityClaimType fromDescription(final String dbData) {
for (final CommunityClaimType t : CommunityClaimType.values()) {
if (t.description.equalsIgnoreCase(dbData)) { return t; }
}
return null;
}
} }

View File

@ -10,12 +10,8 @@ public class CommunityClaimTypeConverter implements AttributeConverter<Community
public String convertToDatabaseColumn(final CommunityClaimType attribute) { public String convertToDatabaseColumn(final CommunityClaimType attribute) {
if (attribute == null) { if (attribute == null) {
return null; return null;
} else if (attribute == CommunityClaimType.managersOnly) {
return "managers-only";
} else if (attribute == CommunityClaimType.membersOnly) {
return "members-only";
} else { } else {
return attribute.toString(); return attribute.getDescription();
} }
} }
@ -23,12 +19,8 @@ public class CommunityClaimTypeConverter implements AttributeConverter<Community
public CommunityClaimType convertToEntityAttribute(final String dbData) { public CommunityClaimType convertToEntityAttribute(final String dbData) {
if (StringUtils.isBlank(dbData)) { if (StringUtils.isBlank(dbData)) {
return null; return null;
} else if (dbData.equalsIgnoreCase("managers-only")) {
return CommunityClaimType.managersOnly;
} else if (dbData.equalsIgnoreCase("members-only")) {
return CommunityClaimType.membersOnly;
} else { } else {
return CommunityClaimType.valueOf(dbData); return CommunityClaimType.fromDescription(dbData);
} }
} }

View File

@ -2,7 +2,23 @@ package eu.dnetlib.openaire.community.db.enums;
public enum CommunityMembershipType { public enum CommunityMembershipType {
open, open("open"),
byInvitation byInvitation("by-invitation");
private final String description;
private CommunityMembershipType(final String description) {
this.description = description;
}
public String getDescription() {
return description;
}
public static CommunityMembershipType fromDescription(final String dbData) {
for (final CommunityMembershipType t : CommunityMembershipType.values()) {
if (t.description.equalsIgnoreCase(dbData)) { return t; }
}
return null;
}
} }

View File

@ -10,10 +10,8 @@ public class CommunityMembershipTypeConverter implements AttributeConverter<Comm
public String convertToDatabaseColumn(final CommunityMembershipType attribute) { public String convertToDatabaseColumn(final CommunityMembershipType attribute) {
if (attribute == null) { if (attribute == null) {
return null; return null;
} else if (attribute == CommunityMembershipType.byInvitation) {
return "by-invitation";
} else { } else {
return attribute.toString(); return attribute.getDescription();
} }
} }
@ -21,10 +19,8 @@ public class CommunityMembershipTypeConverter implements AttributeConverter<Comm
public CommunityMembershipType convertToEntityAttribute(final String dbData) { public CommunityMembershipType convertToEntityAttribute(final String dbData) {
if (StringUtils.isBlank(dbData)) { if (StringUtils.isBlank(dbData)) {
return null; return null;
} else if (dbData.equalsIgnoreCase("by-invitation")) {
return CommunityMembershipType.byInvitation;
} else { } else {
return CommunityMembershipType.valueOf(dbData); return CommunityMembershipType.fromDescription(dbData);
} }
} }

View File

@ -1,8 +0,0 @@
package eu.dnetlib.openaire.community.db.enums;
public enum CommunityStatus {
all,
manager,
members,
hidden
}

View File

@ -25,8 +25,8 @@ import eu.dnetlib.openaire.community.db.enums.CommunityClaimType;
import eu.dnetlib.openaire.community.db.enums.CommunityClaimTypeConverter; import eu.dnetlib.openaire.community.db.enums.CommunityClaimTypeConverter;
import eu.dnetlib.openaire.community.db.enums.CommunityMembershipType; import eu.dnetlib.openaire.community.db.enums.CommunityMembershipType;
import eu.dnetlib.openaire.community.db.enums.CommunityMembershipTypeConverter; import eu.dnetlib.openaire.community.db.enums.CommunityMembershipTypeConverter;
import eu.dnetlib.openaire.community.db.enums.CommunityStatus;
import eu.dnetlib.openaire.community.db.enums.CommunityType; import eu.dnetlib.openaire.community.db.enums.CommunityType;
import eu.dnetlib.openaire.exporter.model.community.CommunityStatus;
@Entity @Entity
@Table(name = "communities") @Table(name = "communities")

View File

@ -14,5 +14,8 @@ public enum CommunityStatus {
manager, manager,
@Schema(description = "visible to RCD managers and to the community users") @Schema(description = "visible to RCD managers and to the community users")
all all,
@Schema(description = "visible only to RCD members")
members
} }

View File

@ -1,6 +1,6 @@
package eu.dnetlib.openaire.exporter.model.community; package eu.dnetlib.openaire.exporter.model.community;
import java.util.Date; import java.time.LocalDateTime;
import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
@ -25,10 +25,10 @@ public class CommunitySummary {
protected String shortName; protected String shortName;
@Schema(description = "community creation date") @Schema(description = "community creation date")
protected Date creationDate; protected LocalDateTime creationDate;
@Schema(description = "community last update date") @Schema(description = "community last update date")
protected Date lastUpdateDate; protected LocalDateTime lastUpdateDate;
@Schema(description = "community description") @Schema(description = "community description")
protected String description; protected String description;
@ -50,8 +50,8 @@ public class CommunitySummary {
final String type, final String type,
final String name, final String name,
final String shortName, final String shortName,
final Date creationDate, final LocalDateTime creationDate,
final Date lastUpdateDate, final LocalDateTime lastUpdateDate,
final String description, final String description,
final String logoUrl, final String logoUrl,
final CommunityStatus status, final CommunityStatus status,
@ -123,19 +123,19 @@ public class CommunitySummary {
this.shortName = shortName; this.shortName = shortName;
} }
public Date getCreationDate() { public LocalDateTime getCreationDate() {
return creationDate; return creationDate;
} }
public void setCreationDate(final Date creationDate) { public void setCreationDate(final LocalDateTime creationDate) {
this.creationDate = creationDate; this.creationDate = creationDate;
} }
public Date getLastUpdateDate() { public LocalDateTime getLastUpdateDate() {
return lastUpdateDate; return lastUpdateDate;
} }
public void setLastUpdateDate(final Date lastUpdateDate) { public void setLastUpdateDate(final LocalDateTime lastUpdateDate) {
this.lastUpdateDate = lastUpdateDate; this.lastUpdateDate = lastUpdateDate;
} }