Merge pull request 'communityAPIExtention' (#10) from communityAPIExtention into master
Reviewed-on: #10
This commit is contained in:
commit
7dd9baf7d0
|
@ -20,7 +20,7 @@ public interface ISClient {
|
|||
|
||||
Map<String, Context> getContextMap(final List<String> type) throws IOException;
|
||||
|
||||
void updateContextParam(String id, String name, String value);
|
||||
void updateContextParam(String id, String name, String value, boolean toEscape);
|
||||
|
||||
void updateContextAttribute(String id, String name, String value);
|
||||
|
||||
|
|
|
@ -105,17 +105,39 @@ public class ISClientImpl implements ISClient {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = {
|
||||
"context-cache", "context-cache-funder"
|
||||
}, allEntries = true)
|
||||
public void updateContextParam(final String id, final String name, final String value) {
|
||||
public void updateContextParam(final String id, final String name, final String value, boolean toEscape) {
|
||||
if(getSize(id, name) > 0){
|
||||
try {
|
||||
_quickSeachProfile(getXQuery(id, name, value));
|
||||
_quickSeachProfile(getXQuery(id, name, value, toEscape));
|
||||
} catch (final ISLookUpException e) {
|
||||
throw new DsmRuntimeException(String.format("unable update context param [id: %s, name: %s, value: %s]", id, name, value), e);
|
||||
throw new DsmRuntimeException(String.format("unable to update context param [id: %s, name: %s, value: %s]", id, name, value), e);
|
||||
}
|
||||
}
|
||||
else{
|
||||
try {
|
||||
_quickSeachProfile(getInsertXQuery(id, name, value,toEscape));
|
||||
} catch (final ISLookUpException e) {
|
||||
throw new DsmRuntimeException(String.format("unable to insert context param [id: %s, name: %s, value: %s]", id, name, value), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private int getSize(String id, String name) {
|
||||
int size = 0;
|
||||
try {
|
||||
size = _quickSeachProfile(String.format("for $x in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType') where $x//context[@id='%s']/param[@name='%s'] return $x", id, name)).size();
|
||||
} catch (ISLookUpException e) {
|
||||
throw new DsmRuntimeException("unable to execute search query", e);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = {
|
||||
|
@ -200,17 +222,46 @@ public class ISClientImpl implements ISClient {
|
|||
|
||||
/// HELPERS
|
||||
|
||||
private String getXQuery(final String id, final String name, final String value) {
|
||||
final Escaper esc = XmlEscapers.xmlContentEscaper();
|
||||
|
||||
private String getInsertXQuery(final String id, final String paramName, final String paramValue, final boolean toEscape) {
|
||||
String value;
|
||||
if(toEscape)
|
||||
value = escape(XmlEscapers.xmlContentEscaper(), paramValue);
|
||||
else
|
||||
value = paramValue;
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
return String.format("update insert <param name='%s'>%s</param> into collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" +
|
||||
"/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']", paramName, value, id);
|
||||
} else {
|
||||
return String.format("update insert <param name='%s'/> into collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" +
|
||||
"/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']", paramName, id);
|
||||
}
|
||||
}
|
||||
|
||||
private String getXQuery(final String id, final String name, final String paramValue, final boolean toEscape) {
|
||||
String value = paramValue;
|
||||
if (toEscape)
|
||||
value = escape(XmlEscapers.xmlContentEscaper(), paramValue);
|
||||
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
return String.format("update replace collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" +
|
||||
"/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']/param[./@name = '%s'] with <param name='%s'>%s</param>", id, name, name, escape(esc, value));
|
||||
"/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']/param[./@name = '%s'] with <param name='%s'>%s</param>", id, name, name, value);
|
||||
} else {
|
||||
return String.format("update replace collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" +
|
||||
"/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']/param[./@name = '%s'] with <param name='%s'/>", id, name, name);
|
||||
}
|
||||
}
|
||||
|
||||
// private String getXQueryNoEscape(final String id, final String name, final String value) {
|
||||
// if (StringUtils.isNotBlank(value)) {
|
||||
// return String.format("update replace collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" +
|
||||
// "/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']/param[./@name = '%s'] with <param name='%s'>%s</param>", id, name, name, value);
|
||||
// } else {
|
||||
// return String.format("update replace collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" +
|
||||
// "/RESOURCE_PROFILE/BODY/CONFIGURATION/context[./@id = '%s']/param[./@name = '%s'] with <param name='%s'/>", id, name, name);
|
||||
// }
|
||||
// }
|
||||
|
||||
private String getConceptXQuery(final String id, final String name, final String value) {
|
||||
final Escaper esc = XmlEscapers.xmlContentEscaper();
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import static eu.dnetlib.openaire.common.ExporterConstants.W;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import eu.dnetlib.openaire.community.selectioncriteria.SelectionCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
|
@ -133,6 +134,44 @@ public class CommunityApiController {
|
|||
communityApiCore.removeCommunityProject(id, projectId);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/community/{id}/projectList", produces = {
|
||||
"application/json"
|
||||
}, method = RequestMethod.POST)
|
||||
@Operation(summary = "associate a list of project to the community",
|
||||
description = "associate a list of project to the community", tags = {
|
||||
C_PJ, W
|
||||
})
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "not found"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||
})
|
||||
public List<CommunityProject> addCommunityProjectList(
|
||||
@PathVariable final String id,
|
||||
@RequestBody final List<CommunityProject> projectList) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
return communityApiCore.addCommunityProjectList(id, projectList);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/community/{id}/projectList", produces = {
|
||||
"application/json"
|
||||
}, method = RequestMethod.DELETE)
|
||||
@Operation(summary = "remove a list of projects from the community",
|
||||
description = "remove a list of projects from the community", tags = {
|
||||
C_PJ, W
|
||||
})
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "not found"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||
})
|
||||
public void deleteCommunityProjectList(
|
||||
@PathVariable final String id,
|
||||
@RequestBody final List<Integer> projectIdList) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
communityApiCore.removeCommunityProjectList(id, projectIdList);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/community/{id}/contentproviders", produces = {
|
||||
"application/json"
|
||||
}, method = RequestMethod.GET)
|
||||
|
@ -184,6 +223,44 @@ public class CommunityApiController {
|
|||
communityApiCore.removeCommunityContentProvider(id, contentproviderId);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/community/{id}/contentprovidersList", produces = {
|
||||
"application/json"
|
||||
}, method = RequestMethod.POST)
|
||||
@Operation(summary = "associate a list of content providers to the community",
|
||||
description = "associate a list of content providers to the community", tags = {
|
||||
C_PJ, W
|
||||
})
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "not found"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||
})
|
||||
public List<CommunityContentprovider> addCommunityContentProvidersList(
|
||||
@PathVariable final String id,
|
||||
@RequestBody final List<CommunityContentprovider> contentprovidersList) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
return communityApiCore.addCommunityContentProvidersList(id, contentprovidersList);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/community/{id}/contentprovidersList", produces = {
|
||||
"application/json"
|
||||
}, method = RequestMethod.DELETE)
|
||||
@Operation(summary = "remove a list of content providers from the community",
|
||||
description = "remove a list of content providers from the community", tags = {
|
||||
C_PJ, W
|
||||
})
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "not found"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||
})
|
||||
public void deleteCommunityContentProvidersList(
|
||||
@PathVariable final String id,
|
||||
@RequestBody final List<Integer> contentProviderIdList) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
communityApiCore.removeCommunityContentProviderList(id, contentProviderIdList);
|
||||
}
|
||||
|
||||
// ADDING CODE FOR COMMUNITY ORGANIZATIONS
|
||||
|
||||
@RequestMapping(value = "/community/{id}/organizations", produces = {
|
||||
|
@ -273,6 +350,101 @@ public class CommunityApiController {
|
|||
|
||||
return communityApiCore.removeCommunitySubjects(id, subjects);
|
||||
}
|
||||
@RequestMapping(value = "/community/{id}/fos", produces = { "application/json" }, method = RequestMethod.POST)
|
||||
@Operation(
|
||||
summary = "associate a fos to the community",
|
||||
description = "associate a fos to the community",
|
||||
tags = { C, W })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "not found"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error") })
|
||||
public CommunityDetails addCommunityFOS(
|
||||
@PathVariable final String id,
|
||||
@RequestBody final List<String> subjects) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
return communityApiCore.addCommunityFOS(id, subjects);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/community/{id}/fos", produces = { "application/json" }, method = RequestMethod.DELETE)
|
||||
@Operation(
|
||||
summary = "remove fos from a community",
|
||||
description = "remove fos from a community",
|
||||
tags = { C, W })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "not found"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error") })
|
||||
public CommunityDetails removeCommunityFOS(
|
||||
@PathVariable final String id,
|
||||
@RequestBody final List<String> subjects) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
return communityApiCore.removeCommunityFOS(id, subjects);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/community/{id}/sdg", produces = { "application/json" }, method = RequestMethod.POST)
|
||||
@Operation(
|
||||
summary = "associate a sdg to the community",
|
||||
description = "associate a sdg to the community",
|
||||
tags = { C, W })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "not found"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error") })
|
||||
public CommunityDetails addCommunitySDG(
|
||||
@PathVariable final String id,
|
||||
@RequestBody final List<String> subjects) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
return communityApiCore.addCommunitySDG(id, subjects);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/community/{id}/sdg", produces = { "application/json" }, method = RequestMethod.DELETE)
|
||||
@Operation(
|
||||
summary = "remove sdg from a community",
|
||||
description = "remove sdg from a community",
|
||||
tags = { C, W })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "not found"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error") })
|
||||
public CommunityDetails removeCommunitySDG(
|
||||
@PathVariable final String id,
|
||||
@RequestBody final List<String> subjects) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
return communityApiCore.removeCommunitySDG(id, subjects);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/community/{id}/advancedConstraint", produces = { "application/json" }, method = RequestMethod.POST)
|
||||
@Operation(
|
||||
summary = "the set of constraints to be used to extend the association between result and community",
|
||||
description = "the set of constraints to be used to extend the association between result and community",
|
||||
tags = { C, W })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "not found"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error") })
|
||||
public CommunityDetails addAdvancedConstraint(
|
||||
@PathVariable final String id,
|
||||
@RequestBody final SelectionCriteria advancedConstraint) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
return communityApiCore.addCommunityAdvancedConstraint(id, advancedConstraint);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/community/{id}/advancedConstraint", produces = { "application/json" }, method = RequestMethod.DELETE)
|
||||
@Operation(
|
||||
summary = "remove the constraints to extend the association result community from a community",
|
||||
description = "remove the constraints to extend the association result community from a community",
|
||||
tags = { C, W })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "not found"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error") })
|
||||
public CommunityDetails removeAdvancedConstraint(
|
||||
@PathVariable final String id) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
return communityApiCore.removeCommunityAdvancedConstraint(id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/community/{id}/zenodocommunities", produces = {
|
||||
"application/json"
|
||||
|
|
|
@ -1,37 +1,10 @@
|
|||
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_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.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.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import eu.dnetlib.openaire.community.selectioncriteria.SelectionCriteria;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -47,6 +20,8 @@ import com.google.common.collect.Sets;
|
|||
|
||||
import eu.dnetlib.openaire.common.ISClient;
|
||||
|
||||
import static eu.dnetlib.openaire.community.CommunityConstants.*;
|
||||
|
||||
@Component
|
||||
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
||||
public class CommunityApiCore {// implements CommunityClient{
|
||||
|
@ -72,6 +47,13 @@ public class CommunityApiCore {// implements CommunityClient{
|
|||
|
||||
}
|
||||
|
||||
private void removeAdvancedConstraint(String id) throws CommunityNotFoundException, CommunityException {
|
||||
cc.getCommunity(id);
|
||||
isClient.updateContextParam(id, CPROFILE_ADVANCED_CONSTRAINT, "", false);
|
||||
cc.removeAdvancedConstraint(id);
|
||||
|
||||
}
|
||||
|
||||
public void setCommunity(final String id, final CommunityWritableProperties details) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
cc.getCommunity(id); // ensure the community exists.
|
||||
|
@ -81,27 +63,39 @@ public class CommunityApiCore {// implements CommunityClient{
|
|||
|
||||
}
|
||||
if (details.getName() != null) {
|
||||
isClient.updateContextParam(id, CSUMMARY_NAME, details.getName());
|
||||
isClient.updateContextParam(id, CSUMMARY_NAME, details.getName(), true);
|
||||
|
||||
}
|
||||
if (details.getDescription() != null) {
|
||||
isClient.updateContextParam(id, CSUMMARY_DESCRIPTION, details.getDescription());
|
||||
isClient.updateContextParam(id, CSUMMARY_DESCRIPTION, details.getDescription(), true);
|
||||
|
||||
}
|
||||
if (details.getLogoUrl() != null) {
|
||||
isClient.updateContextParam(id, CSUMMARY_LOGOURL, details.getLogoUrl());
|
||||
isClient.updateContextParam(id, CSUMMARY_LOGOURL, details.getLogoUrl(), true);
|
||||
|
||||
}
|
||||
if (details.getStatus() != null) {
|
||||
isClient.updateContextParam(id, CSUMMARY_STATUS, details.getStatus().name());
|
||||
isClient.updateContextParam(id, CSUMMARY_STATUS, details.getStatus().name(), true);
|
||||
|
||||
}
|
||||
if (details.getSubjects() != null) {
|
||||
isClient.updateContextParam(id, CPROFILE_SUBJECT, Joiner.on(CSV_DELIMITER).join(details.getSubjects()));
|
||||
isClient.updateContextParam(id, CPROFILE_SUBJECT, Joiner.on(CSV_DELIMITER).join(details.getSubjects()), true);
|
||||
|
||||
}
|
||||
if (details.getFos() != null) {
|
||||
isClient.updateContextParam(id, CPROFILE_FOS, Joiner.on(CSV_DELIMITER).join(details.getFos()), true);
|
||||
|
||||
}
|
||||
if (details.getSdg() != null) {
|
||||
isClient.updateContextParam(id, CPROFILE_SDG, Joiner.on(CSV_DELIMITER).join(details.getSdg()), true);
|
||||
|
||||
}
|
||||
if (details.getAdvancedConstraint() != null) {
|
||||
isClient.updateContextParam(id, CPROFILE_ADVANCED_CONSTRAINT, "<![CDATA[" + new Gson().toJson(details.getAdvancedConstraint()) + "]]>", false);
|
||||
|
||||
}
|
||||
if (details.getMainZenodoCommunity() != null) {
|
||||
isClient.updateContextParam(id, CSUMMARY_ZENODOC, details.getMainZenodoCommunity());
|
||||
isClient.updateContextParam(id, CSUMMARY_ZENODOC, details.getMainZenodoCommunity(), true);
|
||||
}
|
||||
|
||||
cc.updateCommunity(id, details);
|
||||
|
@ -117,8 +111,13 @@ public class CommunityApiCore {// implements CommunityClient{
|
|||
throw new CommunityException("parameters 'id' and project.communityId must be coherent");
|
||||
}
|
||||
|
||||
return updateProject(id, project);
|
||||
|
||||
}
|
||||
|
||||
private CommunityProject updateProject(String id, CommunityProject project) throws CommunityException, CommunityNotFoundException {
|
||||
final TreeMap<Integer, CommunityProject> projects = getCommunityProjectMap(id);
|
||||
final String project_id = project.getId();
|
||||
String project_id = project.getId();
|
||||
|
||||
if (project_id != null && projects.keySet().contains(Integer.valueOf(project_id))){
|
||||
if (project.getName() != null) {
|
||||
|
@ -151,6 +150,24 @@ public class CommunityApiCore {// implements CommunityClient{
|
|||
return project;
|
||||
}
|
||||
|
||||
public List<CommunityProject> addCommunityProjectList(final String id, final List<CommunityProject> projectList) throws CommunityException, CommunityNotFoundException {
|
||||
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");
|
||||
}
|
||||
|
||||
List<CommunityProject> projects = new ArrayList();
|
||||
|
||||
for(CommunityProject project : projectList){
|
||||
projects.add(updateProject(id, project));
|
||||
}
|
||||
|
||||
|
||||
return projects;
|
||||
}
|
||||
|
||||
private String nextId(final Integer id) {
|
||||
return String.valueOf(id + 1);
|
||||
}
|
||||
|
@ -164,6 +181,12 @@ public class CommunityApiCore {// implements CommunityClient{
|
|||
cc.removeFromCategory(id, PROJECTS_ID_SUFFIX, String.valueOf(projectId));
|
||||
}
|
||||
|
||||
public void removeCommunityProjectList(final String id, final List<Integer> projectIdList) throws CommunityException, CommunityNotFoundException {
|
||||
for(Integer projectId: projectIdList){
|
||||
removeCommunityProject(id, projectId);
|
||||
}
|
||||
}
|
||||
|
||||
public List<CommunityContentprovider> getCommunityContentproviders(final String id) throws CommunityException, CommunityNotFoundException {
|
||||
cc.getCommunity(id); // ensure the community exists.
|
||||
return cc.getCommunityInfo(id, CONTENTPROVIDERS_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityDataprovider(id, c));
|
||||
|
@ -174,6 +197,10 @@ public class CommunityApiCore {// implements CommunityClient{
|
|||
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(String id, CommunityContentprovider cp) throws CommunityException, CommunityNotFoundException {
|
||||
final TreeMap<Integer, CommunityContentprovider> cps = getCommunityContentproviderMap(id);
|
||||
final String concept_id = cp.getId();
|
||||
if (concept_id != null && cps.keySet().contains(Integer.valueOf(concept_id))) {
|
||||
|
@ -209,6 +236,30 @@ public class CommunityApiCore {// implements CommunityClient{
|
|||
cc.removeFromCategory(id, CONTENTPROVIDERS_ID_SUFFIX, String.valueOf(contentproviderId));
|
||||
}
|
||||
|
||||
public List<CommunityContentprovider> addCommunityContentProvidersList(String id, List<CommunityContentprovider> contentprovidersList) throws CommunityException, CommunityNotFoundException {
|
||||
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");
|
||||
}
|
||||
|
||||
List<CommunityContentprovider> contentproviders = new ArrayList();
|
||||
|
||||
for(CommunityContentprovider contentProvider : contentprovidersList){
|
||||
contentproviders.add(updateContentprovider(id, contentProvider));
|
||||
}
|
||||
|
||||
|
||||
return contentproviders;
|
||||
}
|
||||
|
||||
public void removeCommunityContentProviderList(final String id, final List<Integer> contentProviderIdList) throws CommunityException, CommunityNotFoundException {
|
||||
for(Integer contentProviderId: contentProviderIdList){
|
||||
removeCommunityContentProvider(id, contentProviderId);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCommunityOrganization(final String id, final Integer organizationId) throws CommunityException, CommunityNotFoundException {
|
||||
final Map<Integer, CommunityOrganization> organizations = getCommunityOrganizationMap(id);
|
||||
if (!organizations.containsKey(organizationId)) {
|
||||
|
@ -258,6 +309,91 @@ public class CommunityApiCore {// implements CommunityClient{
|
|||
return cd;
|
||||
}
|
||||
|
||||
public CommunityDetails addCommunityFOS(final String id, final List<String> foss) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
final CommunityDetails cd = new CommunityDetails();
|
||||
|
||||
final Set<String> current = Sets.newHashSet();
|
||||
if(Optional.ofNullable(cc.getCommunity(id).getFos()).isPresent()){
|
||||
current.addAll(cc.getCommunity(id).getFos());
|
||||
}
|
||||
|
||||
current.addAll(foss);
|
||||
|
||||
cd.setFos(Lists.newArrayList(current));
|
||||
|
||||
setCommunity(id, CommunityWritableProperties.fromDetails(cd));
|
||||
|
||||
return cd;
|
||||
}
|
||||
|
||||
public CommunityDetails removeCommunityFOS(final String id, final List<String> foss) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
final CommunityDetails cd = new CommunityDetails();
|
||||
|
||||
final Set<String> current = Sets.newHashSet(cc.getCommunity(id).getFos());
|
||||
|
||||
current.removeAll(foss);
|
||||
|
||||
cd.setFos(Lists.newArrayList(current));
|
||||
|
||||
setCommunity(id, CommunityWritableProperties.fromDetails(cd));
|
||||
|
||||
return cd;
|
||||
}
|
||||
|
||||
public CommunityDetails addCommunitySDG(final String id, final List<String> sdgs) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
final CommunityDetails cd = new CommunityDetails();
|
||||
final Set<String> current = Sets.newHashSet();
|
||||
if(Optional.ofNullable(cc.getCommunity(id).getSdg()).isPresent()){
|
||||
current.addAll(cc.getCommunity(id).getSdg());
|
||||
}
|
||||
|
||||
current.addAll(sdgs);
|
||||
|
||||
cd.setSdg(Lists.newArrayList(current));
|
||||
|
||||
setCommunity(id, CommunityWritableProperties.fromDetails(cd));
|
||||
|
||||
return cd;
|
||||
}
|
||||
|
||||
public CommunityDetails removeCommunitySDG(final String id, final List<String> sdgs) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
final CommunityDetails cd = new CommunityDetails();
|
||||
|
||||
final Set<String> current = Sets.newHashSet(cc.getCommunity(id).getSdg());
|
||||
|
||||
current.removeAll(sdgs);
|
||||
|
||||
cd.setSdg(Lists.newArrayList(current));
|
||||
|
||||
setCommunity(id, CommunityWritableProperties.fromDetails(cd));
|
||||
|
||||
return cd;
|
||||
}
|
||||
|
||||
public CommunityDetails addCommunityAdvancedConstraint(final String id, final SelectionCriteria advancedCosntraint) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
final CommunityDetails cd = new CommunityDetails();
|
||||
|
||||
cd.setAdvancedConstraint(advancedCosntraint);
|
||||
|
||||
setCommunity(id, CommunityWritableProperties.fromDetails(cd));
|
||||
|
||||
return cd;
|
||||
}
|
||||
|
||||
public CommunityDetails removeCommunityAdvancedConstraint(final String id) throws CommunityNotFoundException, CommunityException {
|
||||
|
||||
removeAdvancedConstraint(id);
|
||||
|
||||
return new CommunityDetails();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@CacheEvict(value = "community-cache", allEntries = true)
|
||||
public void removeCommunityZenodoCommunity(final String id, final Integer zenodoCommId) throws CommunityException, CommunityNotFoundException {
|
||||
|
||||
|
@ -365,4 +501,5 @@ public class CommunityApiCore {// implements CommunityClient{
|
|||
return organization;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@ package eu.dnetlib.openaire.community;
|
|||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.Gson;
|
||||
import eu.dnetlib.openaire.common.ISClient;
|
||||
import eu.dnetlib.openaire.community.selectioncriteria.SelectionCriteria;
|
||||
import eu.dnetlib.openaire.context.Category;
|
||||
import eu.dnetlib.openaire.context.Concept;
|
||||
import eu.dnetlib.openaire.context.Context;
|
||||
|
@ -166,6 +168,13 @@ public class CommunityCommon {
|
|||
|
||||
}
|
||||
|
||||
public void removeAdvancedConstraint(String id) throws CommunityException {
|
||||
final Context context = getContextMap().get(id);
|
||||
context.getParams()
|
||||
.replace(CPROFILE_ADVANCED_CONSTRAINT, Arrays.asList(new Param()
|
||||
.setName(CPROFILE_ADVANCED_CONSTRAINT).setValue(null)));
|
||||
}
|
||||
|
||||
public void updateCommunity(String id, CommunityWritableProperties community) throws CommunityException {
|
||||
final Context context = getContextMap().get(id);
|
||||
|
||||
|
@ -199,6 +208,37 @@ public class CommunityCommon {
|
|||
.setValue(Joiner.on(CSV_DELIMITER)
|
||||
.join(community.getSubjects()))));
|
||||
}
|
||||
if(community.getFos() != null){
|
||||
if (context.getParams().containsKey(CPROFILE_FOS))
|
||||
context.getParams()
|
||||
.replace(CPROFILE_FOS, Arrays.asList(new Param().setName(CPROFILE_FOS)
|
||||
.setValue(Joiner.on(CSV_DELIMITER)
|
||||
.join(community.getFos()))));
|
||||
else
|
||||
context.getParams().put(CPROFILE_FOS, Arrays.asList(new Param().setName(CPROFILE_FOS)
|
||||
.setValue(Joiner.on(CSV_DELIMITER)
|
||||
.join(community.getFos()))));
|
||||
}
|
||||
if(community.getSdg() != null){
|
||||
if(context.getParams().containsKey(CPROFILE_SDG))
|
||||
context.getParams()
|
||||
.replace(CPROFILE_SDG, Arrays.asList(new Param().setName(CPROFILE_SDG)
|
||||
.setValue(Joiner.on(CSV_DELIMITER)
|
||||
.join(community.getSdg()))));
|
||||
else
|
||||
context.getParams().put(CPROFILE_SDG, Arrays.asList(new Param().setName(CPROFILE_SDG)
|
||||
.setValue(Joiner.on(CSV_DELIMITER)
|
||||
.join(community.getSdg()))));
|
||||
}
|
||||
if (community.getAdvancedConstraint() != null) {
|
||||
if(context.getParams().containsKey(CPROFILE_ADVANCED_CONSTRAINT))
|
||||
context.getParams()
|
||||
.replace(CPROFILE_ADVANCED_CONSTRAINT, Arrays.asList(new Param()
|
||||
.setName(CPROFILE_ADVANCED_CONSTRAINT).setValue(new Gson().toJson(community.getAdvancedConstraint()))));
|
||||
else
|
||||
context.getParams().put(CPROFILE_ADVANCED_CONSTRAINT, Arrays.asList(new Param()
|
||||
.setName(CPROFILE_ADVANCED_CONSTRAINT).setValue(new Gson().toJson(community.getAdvancedConstraint()))));
|
||||
}
|
||||
if(community.getMainZenodoCommunity() != null){
|
||||
context.getParams()
|
||||
.replace(CSUMMARY_ZENODOC, Arrays.asList(new Param()
|
||||
|
|
|
@ -32,6 +32,9 @@ public class CommunityConstants {
|
|||
// community profile
|
||||
public final static String CPROFILE_SUBJECT = "subject";
|
||||
public final static String CPROFILE_CREATIONDATE = "creationdate";
|
||||
public final static String CPROFILE_FOS = "fos";
|
||||
public final static String CPROFILE_SDG = "sdg";
|
||||
public final static String CPROFILE_ADVANCED_CONSTRAINT = "advancedConstraint";
|
||||
|
||||
// community project
|
||||
public final static String CPROJECT_FUNDER = "funder";
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
|
||||
import eu.dnetlib.openaire.community.selectioncriteria.SelectionCriteria;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
@JsonAutoDetect
|
||||
|
@ -19,6 +20,16 @@ public class CommunityDetails extends CommunitySummary {
|
|||
@Schema(description = "list of subjects (keywords) that characterise this community")
|
||||
private List<String> subjects;
|
||||
|
||||
@Schema(description = "list of fos that characterise this community")
|
||||
private List<String> fos;
|
||||
|
||||
@Schema(description = "list of sdg that characterise this community")
|
||||
private List<String> sdg;
|
||||
|
||||
@Schema(description = "list of advanced criteria to associate results to this community")
|
||||
private SelectionCriteria advancedConstraint;
|
||||
|
||||
|
||||
public CommunityDetails() {}
|
||||
|
||||
public CommunityDetails(final CommunitySummary summary) {
|
||||
|
@ -52,4 +63,28 @@ public class CommunityDetails extends CommunitySummary {
|
|||
public void setLastUpdateDate(final Date lastUpdateDate) {
|
||||
this.lastUpdateDate = lastUpdateDate;
|
||||
}
|
||||
|
||||
public List<String> getFos() {
|
||||
return fos;
|
||||
}
|
||||
|
||||
public void setFos(List<String> fos) {
|
||||
this.fos = fos;
|
||||
}
|
||||
|
||||
public List<String> getSdg() {
|
||||
return sdg;
|
||||
}
|
||||
|
||||
public void setSdg(List<String> sdg) {
|
||||
this.sdg = sdg;
|
||||
}
|
||||
|
||||
public SelectionCriteria getAdvancedConstraint() {
|
||||
return advancedConstraint;
|
||||
}
|
||||
|
||||
public void setAdvancedConstraint(SelectionCriteria advancedConstraint) {
|
||||
this.advancedConstraint = advancedConstraint;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,15 @@ public class CommunityMappingUtils {
|
|||
if (params.containsKey(CPROFILE_SUBJECT)) {
|
||||
p.setSubjects(splitValues(asValues(params.get(CPROFILE_SUBJECT)), CSV_DELIMITER));
|
||||
}
|
||||
if (params.containsKey(CPROFILE_FOS)) {
|
||||
p.setFos(splitValues(asValues(params.get(CPROFILE_FOS)), CSV_DELIMITER));
|
||||
}
|
||||
if (params.containsKey(CPROFILE_SDG)) {
|
||||
p.setSdg(splitValues(asValues(params.get(CPROFILE_SDG)), CSV_DELIMITER));
|
||||
}
|
||||
if (params.containsKey(CPROFILE_ADVANCED_CONSTRAINT)) {
|
||||
p.setAdvancedConstraint(SelectionCriteria.fromJson(asCsv(params.get(CPROFILE_ADVANCED_CONSTRAINT))));
|
||||
}
|
||||
if (params.containsKey(CPROFILE_CREATIONDATE)){
|
||||
try {
|
||||
p.setCreationDate(org.apache.commons.lang3.time.DateUtils.parseDate(asCsv(params.get(CPROFILE_CREATIONDATE)), pattern));
|
||||
|
|
|
@ -4,8 +4,11 @@ import java.util.List;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
|
||||
import eu.dnetlib.openaire.community.selectioncriteria.SelectionCriteria;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import javax.persistence.criteria.Selection;
|
||||
|
||||
@JsonAutoDetect
|
||||
public class CommunityWritableProperties {
|
||||
|
||||
|
@ -24,6 +27,16 @@ public class CommunityWritableProperties {
|
|||
@Schema(description = "list of subjects (keywords) that characterise this community")
|
||||
private List<String> subjects;
|
||||
|
||||
@Schema(description = "list of fos that characterise this community")
|
||||
private List<String> fos;
|
||||
|
||||
@Schema(description = "list of sdg that characterise this community")
|
||||
private List<String> sdg;
|
||||
|
||||
@Schema(description = "Advanced constraint for the association of results to the community")
|
||||
private SelectionCriteria advancedConstraint;
|
||||
|
||||
|
||||
@Schema(description = "status of the community, drives its visibility")
|
||||
private CommunityStatus status;
|
||||
|
||||
|
@ -39,9 +52,36 @@ public class CommunityWritableProperties {
|
|||
p.setSubjects(details.getSubjects());
|
||||
p.setStatus(details.getStatus());
|
||||
p.setMainZenodoCommunity(details.getZenodoCommunity());
|
||||
p.setFos(details.getFos());
|
||||
p.setSdg(details.getSdg());
|
||||
p.setAdvancedConstraint(details.getAdvancedConstraint());
|
||||
return p;
|
||||
}
|
||||
|
||||
public List<String> getFos() {
|
||||
return fos;
|
||||
}
|
||||
|
||||
public void setFos(List<String> fos) {
|
||||
this.fos = fos;
|
||||
}
|
||||
|
||||
public List<String> getSdg() {
|
||||
return sdg;
|
||||
}
|
||||
|
||||
public void setSdg(List<String> sdg) {
|
||||
this.sdg = sdg;
|
||||
}
|
||||
|
||||
public SelectionCriteria getAdvancedConstraint() {
|
||||
return advancedConstraint;
|
||||
}
|
||||
|
||||
public void setAdvancedConstraint(SelectionCriteria advancedConstraint) {
|
||||
this.advancedConstraint = advancedConstraint;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ management.endpoints.web.base-path = /
|
|||
management.endpoints.web.path-mapping.prometheus = metrics
|
||||
management.endpoints.web.path-mapping.health = health
|
||||
|
||||
|
||||
apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java
|
||||
# ENABLE / DISABLE CONTROLLERS
|
||||
openaire.exporter.enable.dsm = true
|
||||
openaire.exporter.enable.community = true
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
services.is.host = localhost
|
||||
services.is.port = 8280
|
||||
services.is.protocol = http
|
||||
services.is.context = app
|
||||
#services.is.host = localhost
|
||||
services.is.host = dev-openaire.d4science.org
|
||||
#services.is.port = 8280
|
||||
services.is.port = 443
|
||||
#services.is.protocol = http
|
||||
services.is.protocol = https
|
||||
#services.is.context = app
|
||||
services.is.context = is
|
||||
#services.is.baseurl = ${services.is.protocol}://${services.is.host}:${services.is.port}/${services.is.context}/services
|
||||
services.is.baseurl = ${services.is.protocol}://${services.is.host}:${services.is.port}/${services.is.context}/services
|
||||
|
||||
openaire.exporter.isLookupUrl = ${services.is.baseurl}/isLookUp
|
||||
|
@ -15,7 +20,8 @@ openaire.exporter.cxfClientConnectTimeout = 60000
|
|||
openaire.exporter.cxfClientReceiveTimeout = 120000
|
||||
|
||||
# JDBC
|
||||
openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dnet_openaireplus
|
||||
#openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dnet_openaireplus
|
||||
openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dev_openaire_8280
|
||||
openaire.exporter.jdbc.user = dnetapi
|
||||
openaire.exporter.jdbc.pwd = dnetPwd
|
||||
openaire.exporter.jdbc.minIdle = 1
|
||||
|
|
Loading…
Reference in New Issue