This commit is contained in:
Michele Artini 2023-06-19 15:47:48 +02:00
parent 98249be293
commit 6e8f461bec
16 changed files with 224 additions and 792 deletions

View File

@ -29,7 +29,6 @@ import eu.dnetlib.openaire.exporter.model.community.CommunityOrganization;
import eu.dnetlib.openaire.exporter.model.community.CommunityProject;
import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
import eu.dnetlib.openaire.exporter.model.community.CommunityWritableProperties;
import eu.dnetlib.openaire.exporter.model.community.CommunityZenodoCommunity;
import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionCriteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
@ -335,7 +334,7 @@ public class CommunityApiController {
})
public CommunityDetails addCommunitySubjects(
@PathVariable final String id,
@RequestBody final List<String> subjects) throws CommunityException, ResourceNotFoundException {
@RequestBody final String[] subjects) throws CommunityException, ResourceNotFoundException {
return communityService.addCommunitySubjects(id, subjects);
}
@ -353,7 +352,7 @@ public class CommunityApiController {
})
public CommunityDetails removeCommunitySubjects(
@PathVariable final String id,
@RequestBody final List<String> subjects) throws CommunityException, ResourceNotFoundException {
@RequestBody final String[] subjects) throws CommunityException, ResourceNotFoundException {
return communityService.removeCommunitySubjects(id, subjects);
}
@ -371,7 +370,7 @@ public class CommunityApiController {
})
public CommunityDetails addCommunityFOS(
@PathVariable final String id,
@RequestBody final List<String> subjects) throws CommunityException, ResourceNotFoundException {
@RequestBody final String[] subjects) throws CommunityException, ResourceNotFoundException {
return communityService.addCommunityFOS(id, subjects);
}
@ -389,7 +388,7 @@ public class CommunityApiController {
})
public CommunityDetails removeCommunityFOS(
@PathVariable final String id,
@RequestBody final List<String> subjects) throws CommunityException, ResourceNotFoundException {
@RequestBody final String[] subjects) throws CommunityException, ResourceNotFoundException {
return communityService.removeCommunityFOS(id, subjects);
}
@ -407,7 +406,7 @@ public class CommunityApiController {
})
public CommunityDetails addCommunitySDG(
@PathVariable final String id,
@RequestBody final List<String> subjects) throws CommunityException, ResourceNotFoundException {
@RequestBody final String[] subjects) throws CommunityException, ResourceNotFoundException {
return communityService.addCommunitySDG(id, subjects);
}
@ -425,7 +424,7 @@ public class CommunityApiController {
})
public CommunityDetails removeCommunitySDG(
@PathVariable final String id,
@RequestBody final List<String> subjects) throws CommunityException, ResourceNotFoundException {
@RequestBody final String[] subjects) throws CommunityException, ResourceNotFoundException {
return communityService.removeCommunitySDG(id, subjects);
}
@ -465,21 +464,6 @@ public class CommunityApiController {
return communityService.removeCommunityAdvancedConstraint(id);
}
@RequestMapping(value = "/community/{id}/zenodocommunities", produces = {
"application/json"
}, method = RequestMethod.GET)
@Operation(summary = "get the list of Zenodo communities associated to a given community", description = "get the list of Zenodo communities associated to a given community", tags = {
C_ZC, R
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(@PathVariable final String id) throws CommunityException, ResourceNotFoundException {
return communityService.getCommunityZenodoCommunities(id);
}
@RequestMapping(value = "/community/{id}/zenodocommunities", produces = {
"application/json"
}, method = RequestMethod.POST)
@ -491,9 +475,9 @@ public class CommunityApiController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityZenodoCommunity addCommunityZenodoCommunity(
public CommunityDetails addCommunityZenodoCommunity(
@PathVariable final String id,
@RequestBody final CommunityZenodoCommunity zenodocommunity) throws CommunityException, ResourceNotFoundException {
@RequestBody final String zenodocommunity) throws CommunityException, ResourceNotFoundException {
return communityService.addCommunityZenodoCommunity(id, zenodocommunity);
@ -512,7 +496,7 @@ public class CommunityApiController {
})
public void removeCommunityZenodoCommunity(
@PathVariable final String id,
@RequestBody final Integer zenodoCommId) throws CommunityException, ResourceNotFoundException {
@RequestBody final String zenodoCommId) throws CommunityException, ResourceNotFoundException {
communityService.removeCommunityZenodoCommunity(id, zenodoCommId);
@ -529,10 +513,10 @@ public class CommunityApiController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public CommunityOpenAIRECommunities getOpenAireCommunities(
@PathVariable final String zenodoId) throws CommunityException, ResourceNotFoundException {
return communityService.getOpenAIRECommunities(zenodoId);
public CommunityOpenAIRECommunities getOpenAireCommunities(@PathVariable final String zenodoId) throws CommunityException, ResourceNotFoundException {
final CommunityOpenAIRECommunities res = new CommunityOpenAIRECommunities();
res.setZenodoid(zenodoId);
res.setOpenAirecommunitylist(communityService.getOpenAIRECommunities(zenodoId));
return res;
}
}

View File

@ -1,21 +1,11 @@
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.CLABEL;
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;
@ -23,13 +13,10 @@ 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.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 java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@ -149,171 +136,15 @@ public class CommunityApiCore {// implements CommunityClient{
return cc.getCommunityInfo(id, PROJECTS_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityProject(id, c));
}
public CommunityProject addCommunityProject(final String id, final CommunityProject project) throws CommunityException, ResourceNotFoundException {
if (!StringUtils.equalsIgnoreCase(id, project.getCommunityId())) {
throw new CommunityException("parameters 'id' and project.communityId must be coherent");
}
return updateProject(id, project);
}
private CommunityProject updateProject(final String id, final CommunityProject project) throws CommunityException, ResourceNotFoundException {
final TreeMap<Integer, CommunityProject> projects = getCommunityProjectMap(id);
final String project_id = project.getId();
if (project_id != null && projects.keySet().contains(Integer.valueOf(project_id))) {
if (project.getName() != null) {
isClient.updateConceptParam(id + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project_id, CPROJECT_FULLNAME, project.getName());
}
if (project.getAcronym() != null) {
isClient.updateConceptParam(id + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project_id, CPROJECT_ACRONYM, project.getAcronym());
}
if (project.getOpenaireId() != null) {
isClient.updateConceptParam(id + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project_id, OPENAIRE_ID, project.getOpenaireId());
}
if (project.getFunder() != null) {
isClient.updateConceptParam(id + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project_id, CPROJECT_FUNDER, project.getFunder());
}
if (project.getGrantId() != null) {
isClient.updateConceptParam(id + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project_id, CPROJECT_NUMBER, project.getGrantId());
}
} else {
project.setId(nextId(projects != null && !projects.isEmpty() ? projects.lastKey() : 0));
isClient.addConcept(id, id + PROJECTS_ID_SUFFIX, CommunityMappingUtils.asProjectXML(id, project));
}
cc.updateProject(id, project);
return project;
}
public List<CommunityProject> addCommunityProjectList(final String id, final List<CommunityProject> projectList)
throws CommunityException, ResourceNotFoundException {
if (projectList == null || projectList.size() == 0) {
throw new CommunityException("parameter 'projectList' must be present and should contain at least one project");
}
if (!StringUtils.equalsIgnoreCase(id, projectList.get(0).getCommunityId())) {
throw new CommunityException("parameters 'id' and project.communityId must be coherent");
}
final List<CommunityProject> projects = new ArrayList();
for (final CommunityProject project : projectList) {
projects.add(updateProject(id, project));
}
return projects;
}
private String nextId(final Integer id) {
return String.valueOf(id + 1);
}
public void removeCommunityProject(final String id, final Integer projectId) throws CommunityException, ResourceNotFoundException {
final Map<Integer, CommunityProject> projects = getCommunityProjectMap(id);
if (!projects.containsKey(projectId)) {
throw new ResourceNotFoundException(String.format("project '%s' doesn't exist within context '%s'", projectId, id));
}
isClient.removeConcept(id, id + PROJECTS_ID_SUFFIX, id + PROJECTS_ID_SUFFIX + ID_SEPARATOR + projectId);
cc.removeFromCategory(id, PROJECTS_ID_SUFFIX, String.valueOf(projectId));
}
public void removeCommunityProjectList(final String id, final List<Integer> projectIdList) throws CommunityException, ResourceNotFoundException {
for (final Integer projectId : projectIdList) {
removeCommunityProject(id, projectId);
}
}
public List<CommunityContentprovider> getCommunityContentproviders(final String id) throws CommunityException, ResourceNotFoundException {
cc.getCommunity(id); // ensure the community exists.
return cc.getCommunityInfo(id, CONTENTPROVIDERS_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityDataprovider(id, c));
}
public CommunityContentprovider addCommunityContentprovider(final String id, final CommunityContentprovider cp)
throws CommunityException, ResourceNotFoundException {
log.info("content provider to add " + cp.toString());
if (!StringUtils.equalsIgnoreCase(id, cp.getCommunityId())) { throw new CommunityException("parameters 'id' and cp.communityId must be coherent"); }
return updateContentprovider(id, cp);
}
private CommunityContentprovider updateContentprovider(final String id, final CommunityContentprovider cp)
throws CommunityException, ResourceNotFoundException {
final TreeMap<Integer, CommunityContentprovider> cps = getCommunityContentproviderMap(id);
final String concept_id = cp.getId();
if (concept_id != null && cps.keySet().contains(Integer.valueOf(concept_id))) {
if (cp.getName() != null) {
isClient.updateConceptParam(id + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + concept_id, CCONTENTPROVIDER_NAME, cp.getName());
}
if (cp.getOfficialname() != null) {
isClient.updateConceptParam(id + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + concept_id, CCONTENTPROVIDER_OFFICIALNAME, cp.getOfficialname());
}
if (cp.getOpenaireId() != null) {
isClient.updateConceptParam(id + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + concept_id, OPENAIRE_ID, cp.getOpenaireId());
}
if (cp.getSelectioncriteria() != null) {
isClient.updateConceptParamNoEscape(id + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + concept_id, CCONTENTPROVIDER_SELCRITERIA, cp.toXML());
}
} else {
log.info("adding new concept for community " + id);
cp.setId(nextId(!cps.isEmpty() ? cps.lastKey() : 0));
isClient.addConcept(id, id + CONTENTPROVIDERS_ID_SUFFIX, CommunityMappingUtils.asContentProviderXML(id, cp));
}
cc.updateDatasource(id, cp);
return cp;
}
public void removeCommunityContentProvider(final String id, final Integer contentproviderId) throws CommunityException, ResourceNotFoundException {
final Map<Integer, CommunityContentprovider> providers = getCommunityContentproviderMap(id);
if (!providers.containsKey(contentproviderId)) {
throw new ResourceNotFoundException(String.format("content provider '%s' doesn't exist within context '%s'", contentproviderId, id));
}
isClient.removeConcept(id, id + CONTENTPROVIDERS_ID_SUFFIX, id + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + contentproviderId);
cc.removeFromCategory(id, CONTENTPROVIDERS_ID_SUFFIX, String.valueOf(contentproviderId));
}
public List<CommunityContentprovider> addCommunityContentProvidersList(final String id, final List<CommunityContentprovider> contentprovidersList)
throws CommunityException, ResourceNotFoundException {
if (contentprovidersList == null || contentprovidersList.size() == 0) {
throw new CommunityException("parameter 'contentprovidersList' must be present and should contain at least one content provider");
}
if (!StringUtils.equalsIgnoreCase(id, contentprovidersList.get(0).getCommunityId())) {
throw new CommunityException("parameters 'id' and contentprovider.communityId must be coherent");
}
final List<CommunityContentprovider> contentproviders = new ArrayList();
for (final CommunityContentprovider contentProvider : contentprovidersList) {
contentproviders.add(updateContentprovider(id, contentProvider));
}
return contentproviders;
}
public void removeCommunityContentProviderList(final String id, final List<Integer> contentProviderIdList)
throws CommunityException, ResourceNotFoundException {
for (final Integer contentProviderId : contentProviderIdList) {
removeCommunityContentProvider(id, contentProviderId);
}
}
public void removeCommunityOrganization(final String id, final Integer organizationId) throws CommunityException, ResourceNotFoundException {
final Map<Integer, CommunityOrganization> organizations = getCommunityOrganizationMap(id);
if (!organizations.containsKey(organizationId)) {
throw new ResourceNotFoundException(String.format("organization '%s' doesn't exist within context '%s'", organizationId, id));
}
isClient.removeConcept(id, id + ORGANIZATION_ID_SUFFIX, id + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organizationId);
cc.removeFromCategory(id, ORGANIZATION_ID_SUFFIX, String.valueOf(organizationId));
}
public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(final String id) throws CommunityException, ResourceNotFoundException {
return cc.getCommunityZenodoCommunities(id);
@ -482,23 +313,6 @@ public class CommunityApiCore {// implements CommunityClient{
// HELPERS
private TreeMap<Integer, CommunityProject> getCommunityProjectMap(final String id) throws CommunityException, ResourceNotFoundException {
return getCommunityProjects(id).stream()
.collect(Collectors.toMap(p -> Integer.valueOf(p.getId()), Functions.identity(), (p1, p2) -> {
log.warn(String.format("duplicate project found: '%s'", p1.getId()));
return p2;
}, TreeMap::new));
}
private TreeMap<Integer, CommunityContentprovider> getCommunityContentproviderMap(final String id) throws CommunityException, ResourceNotFoundException {
log.info("getting community content provider map");
return getCommunityContentproviders(id).stream()
.collect(Collectors.toMap(cp -> Integer.valueOf(cp.getId()), Functions.identity(), (cp1, cp2) -> {
log.warn(String.format("duplicate content provider found: '%s'", cp1.getId()));
return cp2;
}, TreeMap::new));
}
private TreeMap<Integer, CommunityZenodoCommunity> getZenodoCommunityMap(final String id) throws CommunityException, ResourceNotFoundException {
return getCommunityZenodoCommunities(id).stream()
.collect(Collectors.toMap(cp -> Integer.valueOf(cp.getId()), Functions.identity(), (cp1, cp2) -> {
@ -507,42 +321,4 @@ public class CommunityApiCore {// implements CommunityClient{
}, TreeMap::new));
}
private TreeMap<Integer, CommunityOrganization> getCommunityOrganizationMap(final String id) throws CommunityException, ResourceNotFoundException {
return getCommunityOrganizations(id).stream()
.collect(Collectors.toMap(o -> Integer.valueOf(o.getId()), Functions.identity(), (o1, o2) -> {
log.warn(String.format("duplicate content provider found: '%s'", o1.getId()));
return o2;
}, TreeMap::new));
}
public CommunityOrganization addCommunityOrganization(final String id, final CommunityOrganization organization)
throws CommunityException, ResourceNotFoundException {
if (!StringUtils.equalsIgnoreCase(id, organization.getCommunityId())) {
throw new CommunityException("parameters 'id' and organization.communityId must be coherent");
}
final TreeMap<Integer, CommunityOrganization> cps = getCommunityOrganizationMap(id);
final String organization_id = organization.getId();
if (organization_id != null && cps.keySet().contains(Integer.valueOf(organization_id))) {
if (organization.getName() != null) {
isClient.updateConceptParam(id + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organization_id, CORGANIZATION_NAME, organization.getName());
}
if (organization.getLogo_url() != null) {
isClient.updateConceptParam(id + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organization_id, CORGANIZATION_LOGOURL, Base64.getEncoder()
.encodeToString(organization.getLogo_url().getBytes()));
}
if (organization.getWebsite_url() != null) {
isClient.updateConceptParam(id + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organization_id, CORGANIZATION_WEBSITEURL, Base64.getEncoder()
.encodeToString(organization.getWebsite_url().getBytes()));
}
} else {
organization.setId(nextId(!cps.isEmpty() ? cps.lastKey() : 0));
isClient.addConcept(id, id + ORGANIZATION_ID_SUFFIX, CommunityMappingUtils.asOrganizationXML(id, organization));
}
cc.updateOrganization(id, organization);
return organization;
}
}

View File

@ -1,20 +1,9 @@
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;
@ -23,15 +12,11 @@ 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;
@ -48,10 +33,7 @@ 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;
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
import eu.dnetlib.openaire.exporter.model.community.CommunityDetails;
import eu.dnetlib.openaire.exporter.model.community.CommunityOrganization;
import eu.dnetlib.openaire.exporter.model.community.CommunityProject;
import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
import eu.dnetlib.openaire.exporter.model.community.CommunityWritableProperties;
import eu.dnetlib.openaire.exporter.model.community.CommunityZenodoCommunity;
@ -111,114 +93,6 @@ public class CommunityCommon {
return getCommunityInfo(id, ZENODOCOMMUNITY_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityZenodoCommunity(id, c));
}
public void updateProject(final String communityId, final CommunityProject project) throws CommunityException {
final Context context = getContextMap().get(communityId);
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())));
}
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())));
}
}
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())));
}
}
if (project.getFunder() != null) {
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())));
}
}
});
} else {
final Concept concept = new Concept();
concept.setId(communityId + PROJECTS_ID_SUFFIX + ID_SEPARATOR + project.getId());
concept.setClaim(false);
if (project.getAcronym() != null) {
concept.setLabel(project.getAcronym());
} else {
concept.setLabel("");
}
final Map<String, List<Param>> params = new TreeMap<>();
if (project.getAcronym() != null) {
params.put(CPROJECT_ACRONYM, Arrays.asList(new Param().setName(CPROJECT_ACRONYM)
.setValue(project.getAcronym())));
}
if (project.getName() != null) {
params.put(CPROJECT_FULLNAME, Arrays.asList(new Param()
.setName(CPROJECT_FULLNAME)
.setValue(project.getName())));
}
if (project.getOpenaireId() != null) {
params.put(OPENAIRE_ID, Arrays.asList(new Param()
.setName(OPENAIRE_ID)
.setValue(project.getOpenaireId())));
}
if (project.getFunder() != null) {
params.put(CPROJECT_FUNDER, Arrays.asList(new Param()
.setName(CPROJECT_FUNDER)
.setValue(project.getFunder())));
}
if (project.getGrantId() != null) {
params.put(CPROJECT_NUMBER, Arrays.asList(new Param()
.setName(CPROJECT_NUMBER)
.setValue(project.getGrantId())));
}
concept.setParams(params);
prj.getConcepts().add(concept);
}
}
public void removeAdvancedConstraint(final String id) throws CommunityException {
final Context context = getContextMap().get(id);
context.getParams()
@ -328,195 +202,6 @@ public class CommunityCommon {
cat.get(communityId + category).setConcepts(concepts);
}
public void updateDatasource(final String communityId, final CommunityContentprovider cp) throws CommunityException {
final Context context = getContextMap().get(communityId);
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())));
}
}
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())));
}
}
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())));
}
}
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())));
}
}
}
});
} else {
final Concept concept = new Concept();
concept.setId(communityId + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + cp.getId());
concept.setClaim(false);
concept.setLabel("");
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)));
}
if (cp.getOfficialname() != null) {
params.put(CCONTENTPROVIDER_OFFICIALNAME, Arrays.asList(new Param().setValue(cp.getOfficialname()).setName(CCONTENTPROVIDER_OFFICIALNAME)));
}
if (cp.getOpenaireId() != null) {
params.put(OPENAIRE_ID, Arrays.asList(new Param().setValue(cp.getOpenaireId()).setName(OPENAIRE_ID)));
}
if (cp.getSelectioncriteria() != null) {
params.put(CCONTENTPROVIDER_SELCRITERIA, Arrays.asList(new Param().setValue(cp.toJson()).setName(CCONTENTPROVIDER_SELCRITERIA)));
}
concept.setParams(params);
dts.getConcepts().add(concept);
}
}
public void updateOrganization(final String communityId, final CommunityOrganization organization) throws CommunityException {
final Context context = getContextMap().get(communityId);
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())));
}
}
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()))));
}
}
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()))));
}
}
}
});
} else {
final Concept concept = new Concept();
concept.setId(communityId + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organization.getId());
concept.setClaim(false);
concept.setLabel("");
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)));
}
if (organization.getWebsite_url() != null) {
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(final String communityId, final CommunityZenodoCommunity zc) throws CommunityException {
final Context context = getContextMap().get(communityId);
final Category zcs = context.getCategories().get(communityId + ZENODOCOMMUNITY_ID_SUFFIX);

View File

@ -1,12 +1,9 @@
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;
@ -28,9 +25,7 @@ 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.time.LocalDateTime;
@ -135,7 +130,7 @@ public class CommunityMappingUtils {
final Map<String, List<Param>> p = c.getParams();
final CommunityProject project = new CommunityProject();
project.setCommunityId(communityId);
project.setId(StringUtils.substringAfterLast(c.getId(), ID_SEPARATOR));
// project.setId(StringUtils.substringAfterLast(c.getId(), ID_SEPARATOR));
project.setOpenaireId(firstValue(p, OPENAIRE_ID));
project.setFunder(firstValue(p, CPROJECT_FUNDER));
project.setGrantId(firstValue(p, CPROJECT_NUMBER));
@ -150,7 +145,7 @@ public class CommunityMappingUtils {
final Map<String, List<Param>> p = c.getParams();
final CommunityContentprovider d = new CommunityContentprovider();
d.setCommunityId(communityId);
d.setId(StringUtils.substringAfterLast(c.getId(), ID_SEPARATOR));
// d.setId(StringUtils.substringAfterLast(c.getId(), ID_SEPARATOR));
d.setOpenaireId(firstValue(p, OPENAIRE_ID));
d.setName(firstValue(p, CCONTENTPROVIDER_NAME));
d.setOfficialname(firstValue(p, CCONTENTPROVIDER_OFFICIALNAME));
@ -172,7 +167,7 @@ public class CommunityMappingUtils {
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.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)));
@ -211,38 +206,6 @@ public class CommunityMappingUtils {
.distinct();
}
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(paramXML(CPROJECT_FULLNAME, project.getName()));
sb.append(paramXML(CPROJECT_ACRONYM, project.getAcronym()));
sb.append(paramXML(CPROJECT_NUMBER, project.getGrantId()));
sb.append(paramXML(CPROJECT_FUNDER, project.getFunder()));
sb.append(paramXML(OPENAIRE_ID, project.getOpenaireId()));
sb.append("</concept>\n");
return sb.toString();
}
public static String asContentProviderXML(final String contextId, final CommunityContentprovider ccp) {
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(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(paramXMLNoEscape(CCONTENTPROVIDER_SELCRITERIA, ccp.toXML()));
sb.append("</concept>\n");
log.info(sb.toString());
return sb.toString();
}
public static String asZenodoCommunityXML(final String contextId, final CommunityZenodoCommunity zc) {
final Escaper esc = XmlEscapers.xmlAttributeEscaper();
final StringBuilder sb = new StringBuilder();
@ -255,19 +218,6 @@ public class CommunityMappingUtils {
return sb.toString();
}
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(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("</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

@ -1,5 +1,6 @@
package eu.dnetlib.openaire.community.db;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@ -13,15 +14,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.openaire.community.db.model.DbCommunity;
import eu.dnetlib.openaire.community.db.model.DbDatasource;
import eu.dnetlib.openaire.community.db.model.DbDatasourcePK;
import eu.dnetlib.openaire.community.db.model.DbOrganization;
import eu.dnetlib.openaire.community.db.model.DbProject;
import eu.dnetlib.openaire.community.db.model.DbProjectPK;
import eu.dnetlib.openaire.community.db.model.DbSupportOrg;
import eu.dnetlib.openaire.community.db.repository.DbCommunityRepository;
import eu.dnetlib.openaire.community.db.repository.DbDatasourceRepository;
import eu.dnetlib.openaire.community.db.repository.DbOrganizationRepository;
@ -32,12 +30,10 @@ import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
import eu.dnetlib.openaire.exporter.model.community.CommunityDetails;
import eu.dnetlib.openaire.exporter.model.community.CommunityOpenAIRECommunities;
import eu.dnetlib.openaire.exporter.model.community.CommunityOrganization;
import eu.dnetlib.openaire.exporter.model.community.CommunityProject;
import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
import eu.dnetlib.openaire.exporter.model.community.CommunityWritableProperties;
import eu.dnetlib.openaire.exporter.model.community.CommunityZenodoCommunity;
import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionCriteria;
@Service
@ -45,17 +41,12 @@ import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionC
public class CommunityService {
// TODO
// 1) Aggiungere i campi membership e claim al modello delle api
// 2) Capire come gestire il campo Id (Integer) di CommunityProject
// 3) Gestire paginazione dei progetti
// 4) CommunityContentprovider sono le datasources?
// 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
// 1) Subcommunities: modello e repository
// 2) Subcommunities: importazione tramite profili
// 3) Subcommunities: visualizzazione tramite le context api
// 4) nuova api per settare the mainzenodocommunity
// 5) ricontrollare se tutti i campi del database sono esposti dalle api (modello + mapping)
// 6) Gestire paginazione dei progetti -- getCommunityProjects deve ritornare una pagina
@Autowired
private DbCommunityRepository dbCommunityRepository;
@ -169,7 +160,7 @@ public class CommunityService {
}
public List<CommunityOrganization> getCommunityOrganizations(final String id) throws CommunityException, ResourceNotFoundException {
return dbOrganizationRepository.findByCommunity(id)
return dbSupportOrgRepository.findByCommunity(id)
.stream()
.map(ConvertionUtils::toCommunityOrganiztion)
.collect(Collectors.toList());
@ -177,64 +168,60 @@ public class CommunityService {
public CommunityOrganization addCommunityOrganization(final String id, final CommunityOrganization organization)
throws CommunityException, ResourceNotFoundException {
final DbOrganization o = ConvertionUtils.toDbOrganization(id, organization);
dbOrganizationRepository.save(o);
final DbSupportOrg o = ConvertionUtils.toDbSupportOrg(id, organization);
dbSupportOrgRepository.save(o);
return organization;
}
public List<CommunityOrganization> addCommunityOrganizationList(final String id, final List<CommunityOrganization> orgList)
throws CommunityException, ResourceNotFoundException {
final List<DbOrganization> list = orgList.stream()
.map(o -> ConvertionUtils.toDbOrganization(id, o))
final List<DbSupportOrg> list = orgList.stream()
.map(o -> ConvertionUtils.toDbSupportOrg(id, o))
.collect(Collectors.toList());
dbOrganizationRepository.saveAll(list);
dbSupportOrgRepository.saveAll(list);
return getCommunityOrganizations(id);
}
@Transactional
public CommunityDetails addCommunitySubjects(final String id, final List<String> subjects) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, subjects, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), false);
public CommunityDetails addCommunitySubjects(final String id, final String... subjects) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), false, subjects);
}
@Transactional
public CommunityDetails removeCommunitySubjects(final String id, final List<String> subjects) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, subjects, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), true);
public CommunityDetails removeCommunitySubjects(final String id, final String... subjects) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), true, subjects);
}
@Transactional
public CommunityDetails addCommunityFOS(final String id, final List<String> foss) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, foss, c -> c.getFos(), (c, fos) -> c.setFos(fos), false);
public CommunityDetails addCommunityFOS(final String id, final String... foss) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), false, foss);
}
@Transactional
public CommunityDetails removeCommunityFOS(final String id, final List<String> foss) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, foss, c -> c.getFos(), (c, fos) -> c.setFos(fos), true);
public CommunityDetails removeCommunityFOS(final String id, final String... foss) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), true, foss);
}
@Transactional
public CommunityDetails addCommunitySDG(final String id, final List<String> sdgs) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, sdgs, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), false);
public CommunityDetails addCommunitySDG(final String id, final String... sdgs) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), false, sdgs);
}
@Transactional
public CommunityDetails removeCommunitySDG(final String id, final List<String> sdgs) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, sdgs, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), true);
public CommunityDetails removeCommunitySDG(final String id, final String... sdgs) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), true, sdgs);
}
public CommunityDetails addCommunityAdvancedConstraint(final String id, final SelectionCriteria advancedCosntraint)
throws CommunityException, ResourceNotFoundException {
try {
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
dbEntry.setAdvancedConstraints(new ObjectMapper().writeValueAsString(advancedCosntraint));
dbEntry.setAdvancedConstraints(advancedCosntraint);
dbCommunityRepository.save(dbEntry);
return getCommunity(id);
} catch (final JsonProcessingException e) {
throw new CommunityException("Error converting json");
}
}
@ -245,31 +232,20 @@ public class CommunityService {
return getCommunity(id);
}
public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(final String id) throws CommunityException, ResourceNotFoundException {
// TODO Auto-generated method stub
return null;
public CommunityDetails removeCommunityZenodoCommunity(final String id, final String zenodoCommunity) throws CommunityException, ResourceNotFoundException {
return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), true, zenodoCommunity);
}
public void removeCommunityZenodoCommunity(final String id, final Integer zenodoCommId) throws CommunityException, ResourceNotFoundException {
// TODO Auto-generated method stub
}
public CommunityZenodoCommunity addCommunityZenodoCommunity(final String id, final CommunityZenodoCommunity zc)
public CommunityDetails addCommunityZenodoCommunity(final String id, final String zenodoCommunity)
throws CommunityException, ResourceNotFoundException {
// TODO Auto-generated method stub
return null;
}
public CommunityOpenAIRECommunities getOpenAIRECommunities(final String zenodoId) throws CommunityException, ResourceNotFoundException {
// TODO Auto-generated method stub
return null;
return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), false, zenodoCommunity);
}
private CommunityDetails modifyElementToArrayField(final String id,
final List<String> values,
final Function<DbCommunity, String[]> getter,
final BiConsumer<DbCommunity, String[]> setter,
final boolean remove) throws ResourceNotFoundException, CommunityException {
final boolean remove,
final String... values) throws ResourceNotFoundException, CommunityException {
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
@ -281,9 +257,9 @@ public class CommunityService {
}
}
if (remove) {
tmpList.removeAll(values);
tmpList.removeAll(Arrays.asList(values));
} else {
tmpList.addAll(values);
tmpList.addAll(Arrays.asList(values));
}
setter.accept(dbEntry, tmpList.toArray(new String[tmpList.size()]));
@ -293,4 +269,8 @@ public class CommunityService {
return getCommunity(id);
}
public List<String> getOpenAIRECommunities(final String zenodoId) {
return dbCommunityRepository.findByZenodoId(zenodoId);
}
}

View File

@ -16,6 +16,8 @@ import javax.persistence.Table;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import com.vladmihalcea.hibernate.type.array.StringArrayType;
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
@ -27,6 +29,7 @@ import eu.dnetlib.openaire.exporter.model.community.CommunityClaimType;
import eu.dnetlib.openaire.exporter.model.community.CommunityMembershipType;
import eu.dnetlib.openaire.exporter.model.community.CommunityStatus;
import eu.dnetlib.openaire.exporter.model.community.CommunityType;
import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionCriteria;
@Entity
@Table(name = "communities")
@ -43,8 +46,11 @@ public class DbCommunity implements Serializable {
@Column(name = "id")
private String id;
@Column(name = "label")
private String label;
@Column(name = "name")
private String name;
@Column(name = "shortname")
private String shortName;
@Column(name = "description")
private String description;
@ -79,11 +85,11 @@ public class DbCommunity implements Serializable {
@Type(type = "jsonb")
@Column(name = "adv_constraints")
private String advancedConstraints;
private SelectionCriteria advancedConstraints;
@Type(type = "jsonb")
@Column(name = "remove_constraints")
private String removeConstraints;
private SelectionCriteria removeConstraints;
@Column(name = "main_zenodo_community")
private String mainZenodoCommunity;
@ -92,10 +98,15 @@ public class DbCommunity implements Serializable {
@Column(name = "other_zenodo_communities", columnDefinition = "text[]")
private String[] otherZenodoCommunities;
@CreatedDate
@Column(name = "creation_date")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private LocalDateTime creationDate;
@LastModifiedDate
@Column(name = "last_udate")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private LocalDateTime lastUpdateDate;
@Column(name = "logo_url")
private String logoUrl;
@ -107,12 +118,20 @@ public class DbCommunity implements Serializable {
this.id = id;
}
public String getLabel() {
return label;
public String getName() {
return name;
}
public void setLabel(final String label) {
this.label = label;
public void setName(final String name) {
this.name = name;
}
public String getShortName() {
return shortName;
}
public void setShortName(final String shortName) {
this.shortName = shortName;
}
public String getDescription() {
@ -179,19 +198,19 @@ public class DbCommunity implements Serializable {
this.sdg = sdg;
}
public String getAdvancedConstraints() {
public SelectionCriteria getAdvancedConstraints() {
return advancedConstraints;
}
public void setAdvancedConstraints(final String advancedConstraints) {
public void setAdvancedConstraints(final SelectionCriteria advancedConstraints) {
this.advancedConstraints = advancedConstraints;
}
public String getRemoveConstraints() {
public SelectionCriteria getRemoveConstraints() {
return removeConstraints;
}
public void setRemoveConstraints(final String removeConstraints) {
public void setRemoveConstraints(final SelectionCriteria removeConstraints) {
this.removeConstraints = removeConstraints;
}
@ -219,6 +238,14 @@ public class DbCommunity implements Serializable {
this.creationDate = creationDate;
}
public LocalDateTime getLastUpdateDate() {
return lastUpdateDate;
}
public void setLastUpdateDate(final LocalDateTime lastUpdateDate) {
this.lastUpdateDate = lastUpdateDate;
}
public String getLogoUrl() {
return logoUrl;
}

View File

@ -8,6 +8,10 @@ import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;
import org.hibernate.annotations.Type;
import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionCriteria;
@Entity
@Table(name = "community_datasources")
@IdClass(DbDatasourcePK.class)
@ -26,12 +30,21 @@ public class DbDatasource implements Serializable {
@Column(name = "ds_name")
private String dsName;
@Column(name = "ds_officialname")
private String dsOfficialName;
@Type(type = "jsonb")
@Column(name = "constraints")
private SelectionCriteria constraints;
public DbDatasource() {}
public DbDatasource(final String community, final String dsId, final String dsName) {
public DbDatasource(final String community, final String dsId, final String dsName, final String dsOfficialName, final SelectionCriteria constraints) {
this.community = community;
this.dsId = dsId;
this.dsName = dsName;
this.dsOfficialName = dsOfficialName;
this.constraints = constraints;
}
public String getCommunity() {
@ -58,4 +71,20 @@ public class DbDatasource implements Serializable {
this.dsName = dsName;
}
public String getDsOfficialName() {
return dsOfficialName;
}
public void setDsOfficialName(final String dsOfficialName) {
this.dsOfficialName = dsOfficialName;
}
public SelectionCriteria getConstraints() {
return constraints;
}
public void setConstraints(final SelectionCriteria constraints) {
this.constraints = constraints;
}
}

View File

@ -1,11 +1,17 @@
package eu.dnetlib.openaire.community.db.repository;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import eu.dnetlib.openaire.community.db.model.DbCommunity;
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
public interface DbCommunityRepository extends JpaRepository<DbCommunity, String> {
@Query(value = "select id from communities where $1 = ANY(array_append(other_zenodo_communities, main_zenodo_community))", nativeQuery = true)
List<String> findByZenodoId(String zenodoId);
}

View File

@ -6,14 +6,13 @@ import java.util.Arrays;
import eu.dnetlib.openaire.community.db.model.DbCommunity;
import eu.dnetlib.openaire.community.db.model.DbDatasource;
import eu.dnetlib.openaire.community.db.model.DbOrganization;
import eu.dnetlib.openaire.community.db.model.DbProject;
import eu.dnetlib.openaire.community.db.model.DbSupportOrg;
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
import eu.dnetlib.openaire.exporter.model.community.CommunityDetails;
import eu.dnetlib.openaire.exporter.model.community.CommunityOrganization;
import eu.dnetlib.openaire.exporter.model.community.CommunityProject;
import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionCriteria;
public class ConvertionUtils {
@ -29,25 +28,25 @@ public class ConvertionUtils {
}
public static CommunityDetails CommunityDetails(final DbCommunity c) {
final CommunityDetails details = new CommunityDetails();
populateSummary(details, c);
details.setAdvancedConstraints(SelectionCriteria.fromJson(c.getAdvancedConstraints()));
details.setAdvancedConstraints(c.getAdvancedConstraints());
details.setFos(Arrays.asList(c.getFos()));
details.setSdg(Arrays.asList(c.getSdg()));
details.setSubjects(Arrays.asList(c.getSubjects()));
// TODO: add the new fields
return null;
details.setClaim(c.getClaim());
details.setMembership(c.getMembership());
details.setOtherZenodoCommunities(Arrays.asList(c.getOtherZenodoCommunities()));
return details;
}
private static void populateSummary(final CommunitySummary summary, final DbCommunity c) {
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.setShortName(c.getShortName());
summary.setName(c.getName());
summary.setLastUpdateDate(c.getLastUpdateDate());
summary.setCreationDate(c.getCreationDate());
summary.setQueryId(c.getId() + PIPE_SEPARATOR + c.getLabel());
summary.setQueryId(c.getId() + PIPE_SEPARATOR + c.getShortName());
summary.setType(c.getType().toString());
summary.setDescription(c.getDescription());
summary.setLogoUrl(c.getLogoUrl());
@ -57,19 +56,12 @@ public class ConvertionUtils {
public static CommunityProject toCommunityProject(final DbProject dbEntry) {
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;
}
@ -86,20 +78,11 @@ public class ConvertionUtils {
public static CommunityContentprovider toCommunityContentprovider(final DbDatasource dbEntry) {
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);
ccp.setOfficialname(dbEntry.getDsOfficialName());
ccp.setSelectioncriteria(dbEntry.getConstraints());
return ccp;
}
@ -108,30 +91,26 @@ public class ConvertionUtils {
ds.setCommunity(id);
ds.setDsId(provider.getOpenaireId());
ds.setDsName(provider.getName());
ds.setDsOfficialName(provider.getOfficialname());
ds.setConstraints(provider.getSelectioncriteria());
return ds;
}
public static CommunityOrganization toCommunityOrganiztion(final DbOrganization dbEntry) {
public static CommunityOrganization toCommunityOrganiztion(final DbSupportOrg dbEntry) {
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);
co.setName(dbEntry.getOrgName());
co.setWebsite_url(dbEntry.getOrgUrl());
co.setLogo_url(dbEntry.getOrgLogoUrl());
return co;
}
public static DbOrganization toDbOrganization(final String id, final CommunityOrganization org) {
final DbOrganization dbo = new DbOrganization();
public static DbSupportOrg toDbSupportOrg(final String id, final CommunityOrganization org) {
final DbSupportOrg dbo = new DbSupportOrg();
dbo.setCommunity(id);
dbo.setOrgId(org.getId());
// TODO le Support Orgs non sono ancora gestite
dbo.setOrgName(org.getName());
dbo.setOrgUrl(org.getWebsite_url());
dbo.setOrgLogoUrl(org.getLogo_url());
return dbo;
}

View File

@ -6,7 +6,8 @@ DROP TABLE IF EXISTS communities;
CREATE TABLE communities (
id text PRIMARY KEY,
label text NOT NULL,
name text NOT NULL,
shortname text NOT NULL, -- in the profile is label
description text NOT NULL DEFAULT '',
status text NOT NULL DEFAULT 'hidden', -- all, manager, hidden, members
membership text NOT NULL DEFAULT 'by-invitation', -- open, by-invitation
@ -20,6 +21,7 @@ CREATE TABLE communities (
main_zenodo_community text,
other_zenodo_communities text[],
creation_date timestamp NOT NULL DEFAULT now(),
last_update timestamp NOT NULL DEFAULT now(),
logo_url text
);
@ -37,7 +39,8 @@ CREATE TABLE community_datasources (
community text NOT NULL REFERENCES communities(id),
ds_id text NOT NULL,
ds_name text NOT NULL,
constraints json,
ds_officialname text NOT NULL,
constraints jsonb,
PRIMARY KEY (community, ds_id)
);
@ -55,6 +58,16 @@ CREATE TABLE community_orgs (
PRIMARY KEY (community, org_id)
);
CREATE TABLE community_subs (
sub_id text NOT NULL PRIMARY KEY,
community text NOT NULL REFERENCES communities(id),
label text NOT NULL,
category text NOT NULL,
params jsonb,
parent text REFERENCES community_subs(sub_id) -- NULL for the first level
);
CREATE INDEX community_projects_community ON community_projects(community);
CREATE INDEX community_datasources_community ON community_datasources(community);
CREATE INDEX community_support_orgs_community ON community_support_orgs(community);

View File

@ -19,10 +19,6 @@ public class CommunityContentprovider {
@Schema(description = "the community identifier this content provider belongs to", required = true)
private String communityId;
@NotNull
@Schema(description = "identifies this content provider within the context it belongs to", required = true)
private String id;
@Schema(description = "content provider name", required = false)
private String name;
@ -50,14 +46,6 @@ public class CommunityContentprovider {
this.communityId = communityId;
}
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
public String getName() {
return name;
}
@ -75,7 +63,6 @@ public class CommunityContentprovider {
}
public SelectionCriteria getSelectioncriteria() {
return this.selectioncriteria;
}
@ -86,7 +73,7 @@ public class CommunityContentprovider {
@Override
public String toString() {
return String.format("id %s, name %s, selection criteria %s", this.id, this.name, toJson());
return String.format("id %s, name %s, selection criteria %s", this.openaireId, this.name, toJson());
}
public String toJson() {

View File

@ -29,6 +29,15 @@ public class CommunityDetails extends CommunitySummary {
@Schema(description = "list of advanced criteria to associate results to this community")
private SelectionCriteria advancedConstraints;
@Schema(description = "type of claim")
private CommunityClaimType claim;
@Schema(description = "type of membership")
private CommunityMembershipType membership;
@Schema(description = "other zenodo communities")
private List<String> otherZenodoCommunities;
public CommunityDetails() {}
public CommunityDetails(final CommunitySummary summary) {
@ -86,4 +95,28 @@ public class CommunityDetails extends CommunitySummary {
public void setAdvancedConstraints(final SelectionCriteria advancedConstraints) {
this.advancedConstraints = advancedConstraints;
}
public CommunityClaimType getClaim() {
return claim;
}
public void setClaim(final CommunityClaimType claim) {
this.claim = claim;
}
public CommunityMembershipType getMembership() {
return membership;
}
public void setMembership(final CommunityMembershipType membership) {
this.membership = membership;
}
public List<String> getOtherZenodoCommunities() {
return otherZenodoCommunities;
}
public void setOtherZenodoCommunities(final List<String> otherZenodoCommunities) {
this.otherZenodoCommunities = otherZenodoCommunities;
}
}

View File

@ -17,10 +17,6 @@ public class CommunityOrganization {
@Schema(description = "name of the organization", required = true)
private String name;
@NotNull
@Schema(description = "identifies this organization within the context it belongs to", required = true)
private String id;
@NotNull
@Schema(description = "url of the logo for this organization", required = true)
private String logo_url;
@ -47,15 +43,6 @@ public class CommunityOrganization {
return this;
}
public String getId() {
return id;
}
public CommunityOrganization setId(final String id) {
this.id = id;
return this;
}
public String getLogo_url() {
return logo_url;
}

View File

@ -13,9 +13,6 @@ public class CommunityProject {
@Schema(description = "the community identifier this project belongs to", required = true)
private String communityId;
@Schema(description = "identifies this project within the context it belongs to", required = true)
private String id;
@Schema(description = "project name", required = true)
private String name;
@ -44,14 +41,6 @@ public class CommunityProject {
this.communityId = communityId;
}
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
public String getName() {
return name;
}

View File

@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect;
import io.swagger.v3.oas.annotations.media.Schema;
@JsonAutoDetect
@Deprecated
public class CommunityZenodoCommunity {
@NotNull

View File

@ -3,14 +3,14 @@ package eu.dnetlib.openaire.exporter.model.community.selectioncriteria;
import java.io.Serializable;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@JsonAutoDetect
public class SelectionCriteria implements Serializable {
@ -32,9 +32,7 @@ public class SelectionCriteria implements Serializable {
}
public static SelectionCriteria fromJson(final String json) {
if(StringUtils.isEmpty(json)){
return null;
}
if (StringUtils.isEmpty(json)) { return null; }
try {
return new ObjectMapper().readValue(json, SelectionCriteria.class);
} catch (final JsonProcessingException e) {
@ -43,4 +41,12 @@ public class SelectionCriteria implements Serializable {
}
}
public String toJson() {
try {
return new ObjectMapper().writeValueAsString(this);
} catch (final JsonProcessingException e) {
throw new RuntimeException(e);
}
}
}