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,10 +6,11 @@ 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;
Map<String, Set<String>> getInverseZenodoCommunityMap() throws CommunityException, ResourceNotFoundException;
void dropCache();
void dropCache();
}

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,51 +19,50 @@ 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);
private static final Log log = LogFactory.getLog(CommunityClient.class);
@Autowired
private CommunityCommon communityCommon;
@Autowired
private CommunityCommon communityCommon;
@Override
@Cacheable("community-cache")
public Map<String, Set<String>> getInverseZenodoCommunityMap () throws CommunityException, ResourceNotFoundException {
log.info("Creating the data structure. Not using cache");
final Map<String, Set<String>> inverseListMap = new HashMap<>();
@Override
@Cacheable("community-cache")
public Map<String, Set<String>> getInverseZenodoCommunityMap() throws CommunityException, ResourceNotFoundException {
log.info("Creating the data structure. Not using cache");
final Map<String, Set<String>> inverseListMap = new HashMap<>();
final List<CommunitySummary> communityList = communityCommon.listCommunities();
final List<CommunitySummary> communityList = communityCommon.listCommunities();
for(CommunitySummary cs :communityList){
final String communityId = cs.getId();
List<CommunityZenodoCommunity> czc = communityCommon.getCommunityZenodoCommunities(communityId);
for(CommunityZenodoCommunity zc:czc){
final String zenodoId = zc.getZenodoid();
if(!inverseListMap.containsKey(zenodoId)) {
inverseListMap.put(zc.getZenodoid(),new HashSet<>());
}
inverseListMap.get(zc.getZenodoid()).add(communityId);
}
final String zenodoMainCommunity = communityCommon.getCommunity(communityId).getZenodoCommunity();
if(!inverseListMap.containsKey(zenodoMainCommunity)) {
inverseListMap.put(zenodoMainCommunity,new HashSet<>());
}
for (final CommunitySummary cs : communityList) {
final String communityId = cs.getId();
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<>());
}
inverseListMap.get(zc.getZenodoid()).add(communityId);
}
final String zenodoMainCommunity = communityCommon.getCommunity(communityId).getZenodoCommunity();
if (!inverseListMap.containsKey(zenodoMainCommunity)) {
inverseListMap.put(zenodoMainCommunity, new HashSet<>());
}
inverseListMap.get(zenodoMainCommunity).add(communityId);
}
return inverseListMap;
}
inverseListMap.get(zenodoMainCommunity).add(communityId);
}
return inverseListMap;
}
@Override
@CacheEvict(cacheNames = { "community-cache", "context-cache-community"}, allEntries = true)
@Scheduled(fixedDelayString = "${openaire.exporter.cache.ttl}")
public void dropCache(){
log.debug("dropped community cache");
}
@Override
@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

@ -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");
@ -49,13 +50,12 @@ public class CommunityConstants {
public final static String CCONTENTPROVIDERENABLED_DEFAULT = "true";
public final static String CCONTENTPROVIDER_SELCRITERIA = "selcriteria";
//community zenodo community
// community zenodo community
public final static String CZENODOCOMMUNITY_ID = "zenodoid";
//community organization
// community organization
public final static String CORGANIZATION_NAME = "name";
public final static String CORGANIZATION_LOGOURL = "logourl";
public final static String CORGANIZATION_WEBSITEURL = "websiteurl";
}

View File

@ -1,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());
@ -63,7 +97,7 @@ public class CommunityMappingUtils {
return summary;
}
public static CommunityDetails asCommunityProfile(final Context c) {
public static CommunityDetails asCommunityProfile(final Context c) {
final CommunityDetails p = new CommunityDetails(asCommunitySummary(c));
p.setLastUpdateDate(c.getLastUpdateDate());
@ -78,14 +112,14 @@ public class CommunityMappingUtils {
p.setSdg(splitValues(asValues(params.get(CPROFILE_SDG)), CSV_DELIMITER));
}
if (params.containsKey(CPROFILE_ADVANCED_CONSTRAINT)) {
//In the map the string is the serialization of the json representing the selection criteria so it is a valid json
// In the map the string is the serialization of the json representing the selection criteria so it is a valid json
p.setAdvancedConstraints(SelectionCriteria.fromJson(asCsv(params.get(CPROFILE_ADVANCED_CONSTRAINT))));
}
if (params.containsKey(CPROFILE_CREATIONDATE)){
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());
}
}
@ -121,44 +155,40 @@ public class CommunityMappingUtils {
return d;
}
public static CommunityZenodoCommunity asCommunityZenodoCommunity(final String communityId, final Concept c){
public static CommunityZenodoCommunity asCommunityZenodoCommunity(final String communityId, final Concept c) {
final CommunityZenodoCommunity z = new CommunityZenodoCommunity();
final Map<String, List<Param>> p = c.getParams();
z.setCommunityId(communityId);
z.setId(StringUtils.substringAfterLast(c.getId(), ID_SEPARATOR));
z.setZenodoid(firstValue(p,CZENODOCOMMUNITY_ID));
//z.setName(c.getLabel());
z.setZenodoid(firstValue(p, CZENODOCOMMUNITY_ID));
// z.setName(c.getLabel());
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);
o.setId(StringUtils.substringAfterLast(c.getId(), ID_SEPARATOR));
o.setName(firstValue(p,CORGANIZATION_NAME));
o.setLogo_url(getDecodedUrl(firstValue(p,CORGANIZATION_LOGOURL)));
o.setWebsite_url(getDecodedUrl(firstValue(p,CORGANIZATION_WEBSITEURL)));
o.setName(firstValue(p, CORGANIZATION_NAME));
o.setLogo_url(getDecodedUrl(firstValue(p, CORGANIZATION_LOGOURL)));
o.setWebsite_url(getDecodedUrl(firstValue(p, CORGANIZATION_WEBSITEURL)));
return o;
}
private static String getDecodedUrl(final String encoded_url){
if(encoded_url == null){
return encoded_url;
}
private static String getDecodedUrl(final String 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)
.flatMap(List::stream)
.filter(StringUtils::isNotBlank)
.map(StringUtils::trim)
.collect(Collectors.toList());
.map(Arrays::asList)
.flatMap(List::stream)
.filter(StringUtils::isNotBlank)
.map(StringUtils::trim)
.collect(Collectors.toList());
}
private static String firstValue(final Map<String, List<Param>> p, final String paramName) {
@ -167,11 +197,12 @@ public class CommunityMappingUtils {
private static String asCsv(final List<Param> params) {
return asValues(params)
.collect(Collectors.joining(CSV_DELIMITER));
.collect(Collectors.joining(CSV_DELIMITER));
}
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,14 +227,13 @@ 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()));
sb.append(paramXML(CCONTENTPROVIDER_ENABLED,CCONTENTPROVIDERENABLED_DEFAULT));
sb.append(paramXML(CCONTENTPROVIDER_ENABLED, CCONTENTPROVIDERENABLED_DEFAULT));
sb.append(paramXMLNoEscape(CCONTENTPROVIDER_SELCRITERIA, ccp.toXML()));
sb.append("</concept>\n");
log.info(sb.toString());
@ -214,32 +243,28 @@ 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())));
sb.append(paramXML(CORGANIZATION_WEBSITEURL, Base64.getEncoder().encodeToString(organization.getWebsite_url().getBytes())));
sb.append("</concept>\n");
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;
}