mapping functions

This commit is contained in:
Michele Artini 2023-06-15 11:27:59 +02:00
parent 9e2638c9e4
commit 3edd995e9d
15 changed files with 797 additions and 610 deletions

View File

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

View File

@ -1,5 +1,11 @@
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.LogFactory;
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.CommunityZenodoCommunity;
import java.util.*;
@Component
@Deprecated
public class CommunityClientImpl implements CommunityClient {
private static final Log log = LogFactory.getLog(CommunityClient.class);
@ -31,10 +36,10 @@ public class CommunityClientImpl implements CommunityClient {
final List<CommunitySummary> communityList = communityCommon.listCommunities();
for(CommunitySummary cs :communityList){
for (final CommunitySummary cs : communityList) {
final String communityId = cs.getId();
List<CommunityZenodoCommunity> czc = communityCommon.getCommunityZenodoCommunities(communityId);
for(CommunityZenodoCommunity zc:czc){
final List<CommunityZenodoCommunity> czc = communityCommon.getCommunityZenodoCommunities(communityId);
for (final CommunityZenodoCommunity zc : czc) {
final String zenodoId = zc.getZenodoid();
if (!inverseListMap.containsKey(zenodoId)) {
inverseListMap.put(zc.getZenodoid(), new HashSet<>());
@ -51,10 +56,10 @@ public class CommunityClientImpl implements CommunityClient {
return inverseListMap;
}
@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}")
public void dropCache() {
log.debug("dropped community cache");

View File

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

View File

@ -1,10 +1,50 @@
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.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.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.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.Param;
import org.apache.commons.lang3.StringUtils;
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.*;
@Deprecated
public class CommunityMappingUtils {
private final static String pattern = "yyyy-MM-dd'T'hh:mm:ss";
@ -38,8 +72,8 @@ public class CommunityMappingUtils {
summary.setId(c.getId());
summary.setShortName(c.getLabel());
summary.setLastUpdateDate(c.getLastUpdateDate());
summary.setCreationDate(c.getCreationDate());
// summary.setLastUpdateDate(c.getLastUpdateDate());
// summary.setCreationDate(c.getCreationDate());
summary.setQueryId(c.getId() + PIPE_SEPARATOR + c.getLabel());
summary.setType(c.getType());
@ -85,7 +119,7 @@ public class CommunityMappingUtils {
if (params.containsKey(CPROFILE_CREATIONDATE)) {
try {
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());
}
}
@ -131,8 +165,7 @@ public class CommunityMappingUtils {
return z;
}
public static CommunityOrganization asCommunityOrganization(String id, Concept c) {
public static CommunityOrganization asCommunityOrganization(final String id, final Concept c) {
final Map<String, List<Param>> p = c.getParams();
final CommunityOrganization o = new CommunityOrganization();
o.setCommunityId(id);
@ -145,13 +178,10 @@ public class CommunityMappingUtils {
}
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));
}
private static List<String> splitValues(final Stream<String> stream, final String separator) {
return stream.map(s -> s.split(separator))
.map(Arrays::asList)
@ -171,7 +201,8 @@ public class CommunityMappingUtils {
}
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(StringUtils::trim)
.distinct();
@ -180,10 +211,9 @@ public class CommunityMappingUtils {
public static String asProjectXML(final String contextId, final CommunityProject project) {
final Escaper esc = XmlEscapers.xmlAttributeEscaper();
final StringBuilder sb = new StringBuilder();
sb.append(
String.format(
"<concept claim='false' id='%s%s%s%s' label='%s'>\n",
escape(esc, contextId), PROJECTS_ID_SUFFIX, ID_SEPARATOR, escape(esc, String.valueOf(project.getId())), escape(esc, project.getAcronym())));
sb.append(String
.format("<concept claim='false' id='%s%s%s%s' label='%s'>\n", 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_ACRONYM, project.getAcronym()));
sb.append(paramXML(CPROJECT_NUMBER, project.getGrantId()));
@ -197,10 +227,9 @@ public class CommunityMappingUtils {
log.info("creating the XML for the content provider");
final Escaper esc = XmlEscapers.xmlAttributeEscaper();
final StringBuilder sb = new StringBuilder();
sb.append(
String.format(
"<concept claim='false' id='%s%s%s%s' label='%s'>\n",
escape(esc, contextId), CONTENTPROVIDERS_ID_SUFFIX, ID_SEPARATOR, escape(esc, String.valueOf(ccp.getId())), escape(esc, ccp.getName())));
sb.append(String
.format("<concept claim='false' id='%s%s%s%s' label='%s'>\n", 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(CCONTENTPROVIDER_NAME, ccp.getName()));
sb.append(paramXML(CCONTENTPROVIDER_OFFICIALNAME, ccp.getOfficialname()));
@ -214,24 +243,21 @@ public class CommunityMappingUtils {
public static String asZenodoCommunityXML(final String contextId, final CommunityZenodoCommunity zc) {
final Escaper esc = XmlEscapers.xmlAttributeEscaper();
final StringBuilder sb = new StringBuilder();
sb.append(
String.format(
"<concept claim='false' id='%s%s%s%s' label='%s'>\n",
escape(esc, contextId), ZENODOCOMMUNITY_ID_SUFFIX, ID_SEPARATOR, escape(esc, String.valueOf(zc.getId())), escape(esc, zc.getZenodoid())));
sb.append(String
.format("<concept claim='false' id='%s%s%s%s' label='%s'>\n", 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("</concept>\n");
return sb.toString();
}
public static String asOrganizationXML(final String contextId, CommunityOrganization organization) {
public static String asOrganizationXML(final String contextId, final CommunityOrganization organization) {
final Escaper esc = XmlEscapers.xmlAttributeEscaper();
final StringBuilder sb = new StringBuilder();
sb.append(
String.format(
"<concept claim='false' id='%s%s%s%s' label='%s'>\n",
escape(esc, contextId), ORGANIZATION_ID_SUFFIX, ID_SEPARATOR, escape(esc, String.valueOf(organization.getId())), escape(esc, organization.getName())));
sb.append(String
.format("<concept claim='false' id='%s%s%s%s' label='%s'>\n", 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_LOGOURL, Base64.getEncoder().encodeToString(organization.getLogo_url().getBytes())));
sb.append(paramXML(CORGANIZATION_WEBSITEURL, Base64.getEncoder().encodeToString(organization.getWebsite_url().getBytes())));
@ -239,7 +265,6 @@ public class CommunityMappingUtils {
return sb.toString();
}
private static String paramXML(final String paramName, final String 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
// 6) Capire come gestire il campo Id (Integer) di CommunityOrganization
// 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
private DbCommunityRepository dbCommunityRepository;

View File

@ -1,5 +1,7 @@
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.DbDatasource;
import eu.dnetlib.openaire.community.db.model.DbOrganization;
@ -11,14 +13,40 @@ import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
public class ConvertionUtils {
public static CommunitySummary toSummary(final DbCommunity dbEntry) {
// TODO
return null;
public static CommunitySummary toSummary(final DbCommunity c) {
final CommunitySummary summary = new CommunitySummary();
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) {
// TODO
return null;
final CommunityProject cp = new CommunityProject();
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) {
@ -27,8 +55,22 @@ public class ConvertionUtils {
}
public static CommunityContentprovider toCommunityContentprovider(final DbDatasource dbEntry) {
// TODO
return null;
final CommunityContentprovider ccp = new CommunityContentprovider();
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) {
@ -37,8 +79,18 @@ public class ConvertionUtils {
}
public static CommunityOrganization toCommunityOrganiztion(final DbOrganization dbEntry) {
// TODO
return null;
final CommunityOrganization co = new CommunityOrganization();
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) {

View File

@ -1,7 +1,26 @@
package eu.dnetlib.openaire.community.db.enums;
public enum CommunityClaimType {
managersOnly,
membersOnly,
all
managersOnly("managers-only"),
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) {
if (attribute == null) {
return null;
} else if (attribute == CommunityClaimType.managersOnly) {
return "managers-only";
} else if (attribute == CommunityClaimType.membersOnly) {
return "members-only";
} else {
return attribute.toString();
return attribute.getDescription();
}
}
@ -23,12 +19,8 @@ public class CommunityClaimTypeConverter implements AttributeConverter<Community
public CommunityClaimType convertToEntityAttribute(final String dbData) {
if (StringUtils.isBlank(dbData)) {
return null;
} else if (dbData.equalsIgnoreCase("managers-only")) {
return CommunityClaimType.managersOnly;
} else if (dbData.equalsIgnoreCase("members-only")) {
return CommunityClaimType.membersOnly;
} 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 {
open,
byInvitation
open("open"),
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) {
if (attribute == null) {
return null;
} else if (attribute == CommunityMembershipType.byInvitation) {
return "by-invitation";
} else {
return attribute.toString();
return attribute.getDescription();
}
}
@ -21,10 +19,8 @@ public class CommunityMembershipTypeConverter implements AttributeConverter<Comm
public CommunityMembershipType convertToEntityAttribute(final String dbData) {
if (StringUtils.isBlank(dbData)) {
return null;
} else if (dbData.equalsIgnoreCase("by-invitation")) {
return CommunityMembershipType.byInvitation;
} 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.CommunityMembershipType;
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.exporter.model.community.CommunityStatus;
@Entity
@Table(name = "communities")

View File

@ -14,5 +14,8 @@ public enum CommunityStatus {
manager,
@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;
import java.util.Date;
import java.time.LocalDateTime;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
@ -25,10 +25,10 @@ public class CommunitySummary {
protected String shortName;
@Schema(description = "community creation date")
protected Date creationDate;
protected LocalDateTime creationDate;
@Schema(description = "community last update date")
protected Date lastUpdateDate;
protected LocalDateTime lastUpdateDate;
@Schema(description = "community description")
protected String description;
@ -50,8 +50,8 @@ public class CommunitySummary {
final String type,
final String name,
final String shortName,
final Date creationDate,
final Date lastUpdateDate,
final LocalDateTime creationDate,
final LocalDateTime lastUpdateDate,
final String description,
final String logoUrl,
final CommunityStatus status,
@ -123,19 +123,19 @@ public class CommunitySummary {
this.shortName = shortName;
}
public Date getCreationDate() {
public LocalDateTime getCreationDate() {
return creationDate;
}
public void setCreationDate(final Date creationDate) {
public void setCreationDate(final LocalDateTime creationDate) {
this.creationDate = creationDate;
}
public Date getLastUpdateDate() {
public LocalDateTime getLastUpdateDate() {
return lastUpdateDate;
}
public void setLastUpdateDate(final Date lastUpdateDate) {
public void setLastUpdateDate(final LocalDateTime lastUpdateDate) {
this.lastUpdateDate = lastUpdateDate;
}