diff --git a/apps/dnet-exporter-api/pom.xml b/apps/dnet-exporter-api/pom.xml
index 06fde34d..36a5e924 100644
--- a/apps/dnet-exporter-api/pom.xml
+++ b/apps/dnet-exporter-api/pom.xml
@@ -141,6 +141,12 @@
spring-web
5.3.8
+
+
+ com.vladmihalcea
+ hibernate-types-52
+
+
diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/AbstractExporterController.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/AbstractExporterController.java
index 486ee096..82b1a96b 100644
--- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/AbstractExporterController.java
+++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/AbstractExporterController.java
@@ -16,7 +16,9 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
import eu.dnetlib.openaire.exporter.exceptions.DsmApiException;
+import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
import eu.dnetlib.openaire.exporter.model.dsm.Response;
/**
@@ -28,17 +30,26 @@ public abstract class AbstractExporterController {
@ResponseBody
@ExceptionHandler({
- DsmApiException.class
+ DsmApiException.class, CommunityException.class, Exception.class
})
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
- public ErrorMessage handleDSMException(final Exception e) {
+ public ErrorMessage handle500(final Exception e) {
+ return _handleError(e);
+ }
+
+ @ResponseBody
+ @ExceptionHandler({
+ ResourceNotFoundException.class
+ })
+ @ResponseStatus(value = HttpStatus.NOT_FOUND)
+ public ErrorMessage handle404(final Exception e) {
return _handleError(e);
}
@ResponseBody
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
- public List processValidationError(final MethodArgumentNotValidException e) {
+ public List handle400(final MethodArgumentNotValidException e) {
return e.getBindingResult()
.getFieldErrors()
.stream()
diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ExporterConstants.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ExporterConstants.java
index 29e4e38a..0d3d4a7b 100644
--- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ExporterConstants.java
+++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ExporterConstants.java
@@ -10,6 +10,7 @@ public class ExporterConstants {
public final static String C_PJ = "Community projects";
public final static String C_ZC = "Community Zenodo Communities";
public final static String C_O = "Community Organizations";
+ public final static String C_SUB = "Subcommunities";
public final static String DS = "Datasource";
public final static String API = "Interface";
diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClient.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClient.java
index b4b279a3..9a4ffdd6 100644
--- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClient.java
+++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClient.java
@@ -4,6 +4,7 @@ import java.io.IOException;
import java.util.List;
import java.util.Map;
+import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.openaire.dsm.dao.utils.IndexDsInfo;
import eu.dnetlib.openaire.exporter.model.context.Context;
@@ -13,18 +14,25 @@ public interface ISClient {
String getObjectStoreId(String dsId) throws Exception;
+ @Deprecated
Map getFunderContextMap() throws IOException;
+ @Deprecated
Map getCommunityContextMap() throws IOException;
+ @Deprecated
Map getContextMap(final List type) throws IOException;
+ @Deprecated
void updateContextParam(String id, String name, String value, boolean toEscape);
+ @Deprecated
void updateContextAttribute(String id, String name, String value);
+ @Deprecated
void addConcept(String id, String categoryId, String data);
+ @Deprecated
void removeConcept(String id, String categoryId, String conceptId);
void dropCache();
@@ -38,10 +46,15 @@ public interface ISClient {
* @param value
* new value for the attribute
*/
+ @Deprecated
void updateConceptAttribute(String id, String name, String value);
+ @Deprecated
void updateConceptParam(String id, String name, String value);
+ @Deprecated
void updateConceptParamNoEscape(String id, String name, String value);
+ String getProfile(String profileId) throws ISLookUpException;
+
}
diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClientImpl.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClientImpl.java
index 679b03e0..42bb80a8 100644
--- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClientImpl.java
+++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/common/ISClientImpl.java
@@ -79,18 +79,21 @@ public class ISClientImpl implements ISClient {
@Override
@Cacheable("context-cache-funder")
+ @Deprecated
public Map getFunderContextMap() throws IOException {
return _processContext(_getQuery(config.getFindFunderContexts()));
}
@Override
@Cacheable("context-cache-community")
+ @Deprecated
public Map getCommunityContextMap() throws IOException {
return _processContext(_getQuery(config.getFindCommunityContexts()));
}
@Override
@Cacheable("context-cache")
+ @Deprecated
public Map getContextMap(final List type) throws IOException {
if (Objects.isNull(type) || type.isEmpty()) {
return _processContext(_getQuery(config.getFindContextProfiles()));
@@ -98,16 +101,15 @@ public class ISClientImpl implements ISClient {
try {
final String xqueryTemplate = _getQuery(config.getFindContextProfilesByType());
final String xquery = String.format(xqueryTemplate, type.stream()
- .map(t -> String.format("./RESOURCE_PROFILE/BODY/CONFIGURATION/context/@type = '%s'", t))
- .collect(Collectors.joining(" or ")));
+ .map(t -> String.format("./RESOURCE_PROFILE/BODY/CONFIGURATION/context/@type = '%s'", t))
+ .collect(Collectors.joining(" or ")));
return _processContext(xquery);
- }catch(Exception e){
+ } catch (final Exception e) {
log.error(e.getMessage());
throw new RuntimeException(e);
}
-
}
}
@@ -115,6 +117,7 @@ public class ISClientImpl implements ISClient {
@CacheEvict(value = {
"context-cache", "context-cache-funder"
}, allEntries = true)
+ @Deprecated
public void updateContextParam(final String id, final String name, final String value, final boolean toEscape) {
if (getSize(id, name) > 0) {
try {
@@ -148,6 +151,7 @@ public class ISClientImpl implements ISClient {
@CacheEvict(value = {
"context-cache", "context-cache-funder"
}, allEntries = true)
+ @Deprecated
public void updateContextAttribute(final String id, final String name, final String value) {
final Escaper esc = XmlEscapers.xmlAttributeEscaper();
try {
@@ -162,6 +166,7 @@ public class ISClientImpl implements ISClient {
@CacheEvict(value = {
"context-cache", "context-cache-funder"
}, allEntries = true)
+ @Deprecated
public void addConcept(final String id, final String categoryId, final String data) {
try {
_quickSeachProfile(String.format("update insert %s into collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" +
@@ -175,6 +180,7 @@ public class ISClientImpl implements ISClient {
@CacheEvict(value = {
"context-cache", "context-cache-funder"
}, allEntries = true)
+ @Deprecated
public void removeConcept(final String id, final String categoryId, final String conceptId) {
try {
_quickSeachProfile(String.format("for $concept in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" +
@@ -190,6 +196,7 @@ public class ISClientImpl implements ISClient {
@CacheEvict(value = {
"context-cache", "context-cache-community", "context-cache-funder"
}, allEntries = true)
+ @Deprecated
public void updateConceptAttribute(final String id, final String name, final String value) {
final Escaper esc = XmlEscapers.xmlAttributeEscaper();
try {
@@ -205,6 +212,7 @@ public class ISClientImpl implements ISClient {
@CacheEvict(value = {
"context-cache", "context-cache-funder"
}, allEntries = true)
+ @Deprecated
public void updateConceptParam(final String id, final String name, final String value) {
try {
_quickSeachProfile(getConceptXQuery(id, name, value));
@@ -217,6 +225,7 @@ public class ISClientImpl implements ISClient {
@CacheEvict(value = {
"context-cache", "context-cache-funder"
}, allEntries = true)
+ @Deprecated
public void updateConceptParamNoEscape(final String id, final String name, final String value) {
try {
_quickSeachProfile(getConceptXQueryNoEscape(id, name, value));
@@ -227,6 +236,7 @@ public class ISClientImpl implements ISClient {
/// HELPERS
+ @Deprecated
private String getInsertXQuery(final String id, final String paramName, final String paramValue, final boolean toEscape) {
String value;
if (toEscape) {
@@ -243,6 +253,7 @@ public class ISClientImpl implements ISClient {
}
}
+ @Deprecated
private String getXQuery(final String id, final String name, final String paramValue, final boolean toEscape) {
String value = paramValue;
if (toEscape) {
@@ -269,6 +280,7 @@ public class ISClientImpl implements ISClient {
// }
// }
+ @Deprecated
private String getConceptXQuery(final String id, final String name, final String value) {
final Escaper esc = XmlEscapers.xmlContentEscaper();
if (StringUtils.isNotBlank(value)) {
@@ -280,6 +292,7 @@ public class ISClientImpl implements ISClient {
}
}
+ @Deprecated
private String getConceptXQueryNoEscape(final String id, final String name, final String value) {
if (StringUtils.isNotBlank(value)) {
@@ -291,10 +304,12 @@ public class ISClientImpl implements ISClient {
}
}
+ @Deprecated
private Map _processContext(final String xquery) throws IOException {
return _processContext(new LinkedBlockingQueue<>(), xquery);
}
+ @Deprecated
private Map _processContext(final Queue errors, final String xquery) throws IOException {
try {
return getContextProfiles(errors, xquery).stream()
@@ -312,6 +327,7 @@ public class ISClientImpl implements ISClient {
}
}
+ @Deprecated
private List getContextProfiles(final Queue errors, final String xquery) throws IOException {
log.warn("getContextProfiles(): not using cache");
try {
@@ -335,13 +351,13 @@ public class ISClientImpl implements ISClient {
final List res = Lists.newArrayList();
log.debug(String.format("running xquery:\n%s", xquery));
- try{
+ try {
final List list = isLookUpService.quickSearchProfile(xquery);
if (list != null) {
res.addAll(list);
}
log.debug(String.format("query result size: %s", res.size()));
- }catch(Exception ex){
+ } catch (final Exception ex) {
log.error(ex.getMessage());
throw new ISLookUpException("");
}
@@ -358,4 +374,9 @@ public class ISClientImpl implements ISClient {
log.debug("dropped dsManager IS cache");
}
+ @Override
+ public String getProfile(final String profileId) throws ISLookUpException {
+ return isLookUpService.getResourceProfile(profileId);
+ }
+
}
diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java
index 6793dd72..ae228039 100644
--- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java
+++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java
@@ -4,12 +4,28 @@ import static eu.dnetlib.openaire.common.ExporterConstants.C;
import static eu.dnetlib.openaire.common.ExporterConstants.C_CP;
import static eu.dnetlib.openaire.common.ExporterConstants.C_O;
import static eu.dnetlib.openaire.common.ExporterConstants.C_PJ;
+import static eu.dnetlib.openaire.common.ExporterConstants.C_SUB;
import static eu.dnetlib.openaire.common.ExporterConstants.C_ZC;
import static eu.dnetlib.openaire.common.ExporterConstants.R;
import static eu.dnetlib.openaire.common.ExporterConstants.W;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.data.domain.Page;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import eu.dnetlib.openaire.common.AbstractExporterController;
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
@@ -19,18 +35,8 @@ 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.SubCommunity;
import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionCriteria;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.web.bind.annotation.CrossOrigin;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
-
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
@@ -42,10 +48,10 @@ import io.swagger.v3.oas.annotations.tags.Tag;
})
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
@Tag(name = "OpenAIRE Communities API", description = "the OpenAIRE Community API")
-public class CommunityApiController {
+public class CommunityApiController extends AbstractExporterController {
@Autowired
- private CommunityApiCore communityApiCore;
+ private CommunityService communityService;
@RequestMapping(value = "/community/communities", produces = {
"application/json"
@@ -58,7 +64,34 @@ public class CommunityApiController {
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public List listCommunities() throws CommunityException {
- return communityApiCore.listCommunities();
+ try {
+ return communityService.listCommunities();
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @RequestMapping(value = "/community/", produces = {
+ "application/json"
+ }, method = RequestMethod.POST)
+ @Operation(summary = "add a new community profile", description = "add a new community profile", tags = {
+ C, W
+ })
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "404", description = "not found"),
+ @ApiResponse(responseCode = "500", description = "unexpected error")
+ })
+ public CommunityDetails getCommunity(@RequestBody final CommunityDetails details) throws CommunityException {
+ try {
+ return communityService.newCommunity(details);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{id}", produces = {
@@ -72,15 +105,21 @@ public class CommunityApiController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
- public CommunityDetails getCommunity(@PathVariable final String id) throws CommunityException, ResourceNotFoundException {
- return communityApiCore.getCommunity(id);
+ public CommunityDetails getCommunity(@PathVariable final String id) throws CommunityException {
+ try {
+ return communityService.getCommunity(id);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{id}", produces = {
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "update community details", description = "update community details", tags = {
- C, R
+ C, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@@ -89,12 +128,39 @@ public class CommunityApiController {
})
public void setCommunity(
@PathVariable final String id,
- @RequestBody final CommunityWritableProperties properties) throws CommunityException, ResourceNotFoundException {
-
- communityApiCore.setCommunity(id, properties);
+ @RequestBody final CommunityWritableProperties properties) throws CommunityException {
+ try {
+ communityService.setCommunity(id, properties);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
- @RequestMapping(value = "/community/{id}/projects", produces = {
+ @RequestMapping(value = "/community/{id}", produces = {
+ "application/json"
+ }, method = RequestMethod.DELETE)
+ @Operation(summary = "delete a community", description = "delete 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 void deleteCommunity(@PathVariable final String id, @RequestParam(required = false, defaultValue = "false") final boolean recursive)
+ throws CommunityException {
+ try {
+ communityService.deleteCommunity(id, recursive);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @RequestMapping(value = "/community/{id}/projects/{page}/{size}", produces = {
"application/json"
}, method = RequestMethod.GET)
@Operation(summary = "get community projects", description = "get community projects", tags = {
@@ -105,8 +171,20 @@ public class CommunityApiController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
- public List getCommunityProjects(@PathVariable final String id) throws CommunityException, ResourceNotFoundException {
- return communityApiCore.getCommunityProjects(id);
+ public Page getCommunityProjects(@PathVariable final String id,
+ @PathVariable final Integer page,
+ @PathVariable final Integer size,
+ @RequestParam(required = false) final String funder,
+ @RequestParam(required = false) final String searchFilter,
+ @RequestParam(required = false) final String orderBy)
+ throws CommunityException {
+ try {
+ return communityService.getCommunityProjects(id, funder, searchFilter, page, size, orderBy);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{id}/projects", produces = {
@@ -122,9 +200,15 @@ public class CommunityApiController {
})
public CommunityProject addCommunityProject(
@PathVariable final String id,
- @RequestBody final CommunityProject project) throws CommunityException, ResourceNotFoundException {
+ @RequestBody final CommunityProject project) throws CommunityException {
- return communityApiCore.addCommunityProject(id, project);
+ try {
+ return communityService.addCommunityProject(id, project);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{id}/projects", produces = {
@@ -140,47 +224,83 @@ public class CommunityApiController {
})
public void deleteCommunityProject(
@PathVariable final String id,
- @RequestBody final Integer projectId) throws CommunityException, ResourceNotFoundException {
-
- communityApiCore.removeCommunityProject(id, projectId);
+ @RequestParam final String projectId) throws CommunityException {
+ try {
+ communityService.removeCommunityProjects(id, projectId);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{id}/projectList", produces = {
- "application/json"
+ "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
+ @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")
+ @ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "404", description = "not found"),
+ @ApiResponse(responseCode = "500", description = "unexpected error")
})
- public List addCommunityProjectList(
- @PathVariable final String id,
- @RequestBody final List projectList) throws CommunityException, ResourceNotFoundException {
-
- return communityApiCore.addCommunityProjectList(id, projectList);
+ public CommunityProject[] addCommunityProjectList(
+ @PathVariable final String id,
+ @RequestBody final CommunityProject[] projects) throws CommunityException {
+ try {
+ communityService.addCommunityProjects(id, projects);
+ return projects;
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{id}/projectList", produces = {
- "application/json"
+ "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
+ @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")
+ @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 projectIdList) throws CommunityException, ResourceNotFoundException {
+ @PathVariable final String id,
+ @RequestBody final String[] projectIdList) throws CommunityException {
+ try {
+ communityService.removeCommunityProjects(id, projectIdList);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
- communityApiCore.removeCommunityProjectList(id, projectIdList);
+ @RequestMapping(value = "/community/{id}/funders", produces = {
+ "application/json"
+ }, method = RequestMethod.GET)
+ @Operation(summary = "get the funders of the projects of a community", description = "get the funders of the projects of a community", tags = {
+ C_PJ, R
+ })
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "404", description = "not found"),
+ @ApiResponse(responseCode = "500", description = "unexpected error")
+ })
+ public List getCommunityFunders(@PathVariable final String id)
+ throws CommunityException {
+ try {
+ return communityService.getCommunityFunders(id);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{id}/contentproviders", produces = {
@@ -194,8 +314,14 @@ public class CommunityApiController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
- public List getCommunityContentproviders(@PathVariable final String id) throws CommunityException, ResourceNotFoundException {
- return communityApiCore.getCommunityContentproviders(id);
+ public List getCommunityContentproviders(@PathVariable final String id) throws CommunityException {
+ try {
+ return communityService.getCommunityContentproviders(id);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{id}/contentproviders", produces = {
@@ -211,9 +337,16 @@ public class CommunityApiController {
})
public CommunityContentprovider addCommunityContentprovider(
@PathVariable final String id,
- @RequestBody final CommunityContentprovider contentprovider) throws CommunityException, ResourceNotFoundException {
+ @RequestBody final CommunityContentprovider contentprovider) throws CommunityException {
- return communityApiCore.addCommunityContentprovider(id, contentprovider);
+ try {
+ communityService.addCommunityContentProviders(id, contentprovider);
+ return contentprovider;
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{id}/contentproviders", produces = {
@@ -229,47 +362,62 @@ public class CommunityApiController {
})
public void removeCommunityContentprovider(
@PathVariable final String id,
- @RequestBody final Integer contentproviderId) throws CommunityException, ResourceNotFoundException {
-
- communityApiCore.removeCommunityContentProvider(id, contentproviderId);
+ @RequestParam final String contentproviderId) throws CommunityException {
+ try {
+ communityService.removeCommunityContentProviders(id, contentproviderId);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{id}/contentprovidersList", produces = {
- "application/json"
+ "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
+ @Operation(summary = "associate a list of content providers to the community", description = "associate a list of content providers to the community", tags = {
+ C_CP, W
})
@ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "OK"),
- @ApiResponse(responseCode = "404", description = "not found"),
- @ApiResponse(responseCode = "500", description = "unexpected error")
+ @ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "404", description = "not found"),
+ @ApiResponse(responseCode = "500", description = "unexpected error")
})
- public List addCommunityContentProvidersList(
- @PathVariable final String id,
- @RequestBody final List contentprovidersList) throws CommunityException, ResourceNotFoundException {
+ public CommunityContentprovider[] addCommunityContentProvidersList(
+ @PathVariable final String id,
+ @RequestBody final CommunityContentprovider[] contentprovidersList) throws CommunityException {
- return communityApiCore.addCommunityContentProvidersList(id, contentprovidersList);
+ try {
+ communityService.addCommunityContentProviders(id, contentprovidersList);
+ return contentprovidersList;
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{id}/contentprovidersList", produces = {
- "application/json"
+ "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
+ @Operation(summary = "remove a list of content providers from the community", description = "remove a list of content providers from the community", tags = {
+ C_CP, W
})
@ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "OK"),
- @ApiResponse(responseCode = "404", description = "not found"),
- @ApiResponse(responseCode = "500", description = "unexpected error")
+ @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 contentProviderIdList) throws CommunityException, ResourceNotFoundException {
-
- communityApiCore.removeCommunityContentProviderList(id, contentProviderIdList);
+ @PathVariable final String id,
+ @RequestBody final String[] contentProviderIdList) throws CommunityException {
+ try {
+ communityService.removeCommunityContentProviders(id, contentProviderIdList);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
// ADDING CODE FOR COMMUNITY ORGANIZATIONS
@@ -285,8 +433,14 @@ public class CommunityApiController {
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
- public List getCommunityOrganizations(@PathVariable final String id) throws CommunityException, ResourceNotFoundException {
- return communityApiCore.getCommunityOrganizations(id);
+ public List getCommunityOrganizations(@PathVariable final String id) throws CommunityException {
+ try {
+ return communityService.getCommunityOrganizations(id);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{id}/organizations", produces = {
@@ -302,9 +456,40 @@ public class CommunityApiController {
})
public CommunityOrganization addCommunityOrganization(
@PathVariable final String id,
- @RequestBody final CommunityOrganization organization) throws CommunityException, ResourceNotFoundException {
+ @RequestBody final CommunityOrganization organization) throws CommunityException {
+ try {
+ communityService.addCommunityOrganizations(id, organization);
+ return organization;
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
- return communityApiCore.addCommunityOrganization(id, organization);
+ @RequestMapping(value = "/community/{id}/organizationList", produces = {
+ "application/json"
+ }, method = RequestMethod.POST)
+ @Operation(summary = "associate a list of organizations to the community", description = "associate a list of organizations to the community", tags = {
+ C_O, W
+ })
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "404", description = "not found"),
+ @ApiResponse(responseCode = "500", description = "unexpected error")
+ })
+ public CommunityOrganization[] addCommunityOrganizationList(
+ @PathVariable final String id,
+ @RequestBody final CommunityOrganization[] orgs) throws CommunityException {
+
+ try {
+ communityService.addCommunityOrganizations(id, orgs);
+ return orgs;
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{id}/organizations", produces = {
@@ -320,10 +505,39 @@ public class CommunityApiController {
})
public void removeCommunityOrganization(
@PathVariable final String id,
- @RequestBody final Integer organizationId) throws CommunityException, ResourceNotFoundException {
-
- communityApiCore.removeCommunityOrganization(id, organizationId);
+ @RequestParam final String organizationName) throws CommunityException {
+ try {
+ communityService.removeCommunityOrganizations(id, organizationName);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
+
+ @RequestMapping(value = "/community/{id}/organizationList", produces = {
+ "application/json"
+ }, method = RequestMethod.DELETE)
+ @Operation(summary = "remove a list of associations between some organizations and the community", description = "remove a list of associations between some organizations and the community", tags = {
+ C_O, W
+ })
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "404", description = "not found"),
+ @ApiResponse(responseCode = "500", description = "unexpected error")
+ })
+ public void removeCommunityOrganizationList(
+ @PathVariable final String id,
+ @RequestBody final String[] orgNames) throws CommunityException {
+ try {
+ communityService.removeCommunityOrganizations(id, orgNames);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
// **********************
@RequestMapping(value = "/community/{id}/subjects", produces = {
@@ -339,9 +553,15 @@ public class CommunityApiController {
})
public CommunityDetails addCommunitySubjects(
@PathVariable final String id,
- @RequestBody final List subjects) throws CommunityException, ResourceNotFoundException {
+ @RequestBody final String[] subjects) throws CommunityException {
- return communityApiCore.addCommunitySubjects(id, subjects);
+ try {
+ return communityService.addCommunitySubjects(id, subjects);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{id}/subjects", produces = {
@@ -357,119 +577,204 @@ public class CommunityApiController {
})
public CommunityDetails removeCommunitySubjects(
@PathVariable final String id,
- @RequestBody final List subjects) throws CommunityException, ResourceNotFoundException {
+ @RequestBody final String[] subjects) throws CommunityException {
- 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 subjects) throws CommunityException, ResourceNotFoundException {
-
- return communityApiCore.addCommunityFOS(id, subjects);
+ try {
+ return communityService.removeCommunitySubjects(id, subjects);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
- @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 subjects) throws CommunityException, ResourceNotFoundException {
-
- 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 subjects) throws CommunityException, ResourceNotFoundException {
-
- 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 subjects) throws CommunityException, ResourceNotFoundException {
-
- 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, ResourceNotFoundException {
-
- 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, ResourceNotFoundException {
-
- return communityApiCore.removeCommunityAdvancedConstraint(id);
- }
-
- @RequestMapping(value = "/community/{id}/zenodocommunities", produces = {
+ @RequestMapping(value = "/community/{id}/fos", 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
+ }, 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 List getCommunityZenodoCommunities(@PathVariable final String id) throws CommunityException, ResourceNotFoundException {
- return communityApiCore.getCommunityZenodoCommunities(id);
+ public CommunityDetails addCommunityFOS(
+ @PathVariable final String id,
+ @RequestBody final String[] subjects) throws CommunityException {
+
+ try {
+ return communityService.addCommunityFOS(id, subjects);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @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 String[] subjects) throws CommunityException {
+
+ try {
+ return communityService.removeCommunityFOS(id, subjects);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @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 String[] subjects) throws CommunityException {
+
+ try {
+ return communityService.addCommunitySDG(id, subjects);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @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 String[] subjects) throws CommunityException {
+
+ try {
+ return communityService.removeCommunitySDG(id, subjects);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @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 {
+
+ try {
+ return communityService.addCommunityAdvancedConstraint(id, advancedConstraint);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @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 {
+
+ try {
+ return communityService.removeCommunityAdvancedConstraint(id);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @RequestMapping(value = "/community/{id}/removeConstraint", produces = {
+ "application/json"
+ }, method = RequestMethod.POST)
+ @Operation(summary = "the set of constraints to be used to remove the association between result and community", description = "the set of constraints to be used to remove 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 addRemoveConstraint(
+ @PathVariable final String id,
+ @RequestBody final SelectionCriteria removeConstraint) throws CommunityException {
+
+ try {
+ return communityService.addCommunityRemoveConstraint(id, removeConstraint);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @RequestMapping(value = "/community/{id}/removeConstraint", produces = {
+ "application/json"
+ }, method = RequestMethod.DELETE)
+ @Operation(summary = "remove the constraints to remove the association beetween result and community", description = "remove the constraints to remove the association beetween 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 removeRemoveConstraint(@PathVariable final String id) throws CommunityException {
+
+ try {
+ return communityService.removeCommunityRemoveConstraint(id);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{id}/zenodocommunities", produces = {
@@ -483,11 +788,18 @@ 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 {
+ @RequestParam(required = false, defaultValue = "false") final boolean main,
+ @RequestParam final String zenodocommunity) throws CommunityException {
- return communityApiCore.addCommunityZenodoCommunity(id, zenodocommunity);
+ try {
+ return communityService.addCommunityZenodoCommunity(id, zenodocommunity, main);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@@ -504,10 +816,15 @@ public class CommunityApiController {
})
public void removeCommunityZenodoCommunity(
@PathVariable final String id,
- @RequestBody final Integer zenodoCommId) throws CommunityException, ResourceNotFoundException {
-
- communityApiCore.removeCommunityZenodoCommunity(id, zenodoCommId);
-
+ @RequestParam(required = false, defaultValue = "false") final boolean main,
+ @RequestParam final String zenodocommunity) throws CommunityException {
+ try {
+ communityService.removeCommunityZenodoCommunity(id, zenodocommunity, main);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
@RequestMapping(value = "/community/{zenodoId}/openairecommunities", produces = {
@@ -521,10 +838,228 @@ 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 communityApiCore.getOpenAIRECommunities(zenodoId);
-
+ public CommunityOpenAIRECommunities getOpenAireCommunities(@PathVariable final String zenodoId) throws CommunityException {
+ try {
+ final CommunityOpenAIRECommunities res = new CommunityOpenAIRECommunities();
+ res.setZenodoid(zenodoId);
+ res.setOpenAirecommunitylist(communityService.getOpenAIRECommunitiesByZenodoId(zenodoId));
+ return res;
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
}
+
+ // APIs to manage the propagationOrganizationCommunityMap
+ @RequestMapping(value = "/propagationOrganizationCommunityMap", produces = {
+ "application/json"
+ }, method = RequestMethod.GET)
+ @Operation(summary = "Get the propagationOrganizationCommunityMap", description = "propagationOrganizationCommunityMap", tags = {
+ C_O, R
+ })
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "404", description = "not found"),
+ @ApiResponse(responseCode = "500", description = "unexpected error")
+ })
+ public Map> getPropagationOrganizationCommunityMap() throws CommunityException {
+ try {
+ return communityService.getPropagationOrganizationCommunityMap();
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @RequestMapping(value = "/community/{id}/propagationOrganizations", produces = {
+ "application/json"
+ }, method = RequestMethod.GET)
+ @Operation(summary = "try { return the propagation organizations of a community", description = "try { return the propagation organizations of a community", tags = {
+ C_O, R
+ })
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "404", description = "not found"),
+ @ApiResponse(responseCode = "500", description = "unexpected error")
+ })
+ public Set getPropagationOrganizationsForCommunity(@PathVariable final String id) throws CommunityException {
+ try {
+ return communityService.getPropagationOrganizationsForCommunity(id);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @RequestMapping(value = "/community/{id}/propagationOrganizations", produces = {
+ "application/json"
+ }, method = RequestMethod.POST)
+ @Operation(summary = "add an organization to the propagationOrganizationCommunityMap", description = "add an organization to the propagationOrganizationCommunityMap", tags = {
+ C_O, W
+ })
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "404", description = "not found"),
+ @ApiResponse(responseCode = "500", description = "unexpected error")
+ })
+ public Set addPropagationOrganizationForCommunity(@PathVariable final String id,
+ @RequestParam final String organizationId) throws CommunityException {
+
+ try {
+ return communityService.addPropagationOrganizationForCommunity(id, organizationId.split(","));
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @RequestMapping(value = "/community/{id}/propagationOrganizations", produces = {
+ "application/json"
+ }, method = RequestMethod.DELETE)
+ @Operation(summary = "delete an organization to the propagationOrganizationCommunityMap", description = "delete an organization to the propagationOrganizationCommunityMap", tags = {
+ C_O, W
+ })
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "404", description = "not found"),
+ @ApiResponse(responseCode = "500", description = "unexpected error")
+ })
+ public Set removePropagationOrganizationForCommunity(@PathVariable final String id,
+ @RequestParam final String organizationId) throws CommunityException {
+
+ try {
+ return communityService.removePropagationOrganizationForCommunity(id, organizationId.split(","));
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ // APIs to manage the sub communities
+
+ @RequestMapping(value = "/community/{id}/subcommunities", produces = {
+ "application/json"
+ }, method = RequestMethod.GET)
+ @Operation(summary = "get the list of subcommunities for a given community", description = "get the list of subcommunities for a given community", tags = {
+ C_SUB, R
+ })
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "404", description = "not found"),
+ @ApiResponse(responseCode = "500", description = "unexpected error")
+ })
+ public List getSubCommunities(@PathVariable final String id, @RequestParam(required = false, defaultValue = "false") final boolean all)
+ throws CommunityException {
+ try {
+ return communityService.getSubCommunities(id)
+ .stream()
+ .filter(sc -> all || sc.isBrowsable())
+ .collect(Collectors.toList());
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @RequestMapping(value = "/community/{id}/subcommunities", produces = {
+ "application/json"
+ }, method = RequestMethod.POST)
+ @Operation(summary = "associate a subcommunity to the community", description = "associate a subcommunity to the community", tags = {
+ C_SUB, W
+ })
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "404", description = "not found"),
+ @ApiResponse(responseCode = "500", description = "unexpected error")
+ })
+ public SubCommunity addSubCommunity(
+ @PathVariable final String id,
+ @RequestBody final SubCommunity subcommunity) throws CommunityException {
+ try {
+ communityService.addSubCommunities(id, subcommunity);
+ return subcommunity;
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @RequestMapping(value = "/community/{id}/subcommunitiesList", produces = {
+ "application/json"
+ }, method = RequestMethod.POST)
+ @Operation(summary = "associate a list of subcommunities to the community", description = "associate a list of subcommunities to the community", tags = {
+ C_SUB, W
+ })
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "404", description = "not found"),
+ @ApiResponse(responseCode = "500", description = "unexpected error")
+ })
+ public SubCommunity[] addSubCommunityList(
+ @PathVariable final String id,
+ @RequestBody final SubCommunity[] subcommunities) throws CommunityException {
+
+ try {
+ communityService.addSubCommunities(id, subcommunities);
+ return subcommunities;
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @RequestMapping(value = "/community/{id}/subcommunities", produces = {
+ "application/json"
+ }, method = RequestMethod.DELETE)
+ @Operation(summary = "remove the association between a subcommunity and the community", description = "remove the association between a subcommunity and the community", tags = {
+ C_SUB, W
+ })
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "404", description = "not found"),
+ @ApiResponse(responseCode = "500", description = "unexpected error")
+ })
+ public void removeSubCommunity(
+ @PathVariable final String id,
+ @RequestParam final String subCommunityId) throws CommunityException {
+ try {
+ communityService.removeSubCommunities(id, subCommunityId);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
+ @RequestMapping(value = "/community/{id}/subcommunitiesList", produces = {
+ "application/json"
+ }, method = RequestMethod.DELETE)
+ @Operation(summary = "remove a list of associations between some subcommunities and the community", description = "remove a list of associations between some subcommunities and the community", tags = {
+ C_SUB, W
+ })
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "404", description = "not found"),
+ @ApiResponse(responseCode = "500", description = "unexpected error")
+ })
+ public void removeSubcommunities(
+ @PathVariable final String id,
+ @RequestBody final String[] subCommunityIdList) throws CommunityException {
+ try {
+ communityService.removeSubCommunities(id, subCommunityIdList);
+ } catch (final ResourceNotFoundException e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new CommunityException(e);
+ }
+ }
+
}
diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiCore.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiCore.java
deleted file mode 100644
index 3f0d8dd5..00000000
--- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiCore.java
+++ /dev/null
@@ -1,517 +0,0 @@
-package eu.dnetlib.openaire.community;
-
-import java.util.*;
-import java.util.stream.Collectors;
-
-import com.google.gson.Gson;
-
-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;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.cache.annotation.CacheEvict;
-import org.springframework.stereotype.Component;
-
-import com.google.common.base.Functions;
-import com.google.common.base.Joiner;
-import com.google.common.collect.Lists;
-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{
-
- private static final Log log = LogFactory.getLog(CommunityApiCore.class);
-
- @Autowired
- private CommunityClient cci;
-
- @Autowired
- private ISClient isClient;
-
- @Autowired
- private CommunityCommon cc;
-
- public List listCommunities() throws CommunityException {
- return cc.listCommunities();
-
- }
-
- public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException {
- return cc.getCommunity(id);
-
- }
-
- private void removeAdvancedConstraint(String id) throws ResourceNotFoundException, 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, ResourceNotFoundException {
-
- cc.getCommunity(id); // ensure the community exists.
-
- if (details.getShortName() != null) {
- isClient.updateContextAttribute(id, CLABEL, details.getShortName());
-
- }
- if (details.getName() != null) {
- isClient.updateContextParam(id, CSUMMARY_NAME, details.getName(), true);
-
- }
- if (details.getDescription() != null) {
- isClient.updateContextParam(id, CSUMMARY_DESCRIPTION, details.getDescription(), true);
-
- }
- if (details.getLogoUrl() != null) {
- isClient.updateContextParam(id, CSUMMARY_LOGOURL, details.getLogoUrl(), true);
-
- }
- if (details.getStatus() != null) {
- 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()), 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.getAdvancedConstraints() != null) {
- isClient.updateContextParam(id, CPROFILE_ADVANCED_CONSTRAINT, "", false);
-
- }
- if (details.getMainZenodoCommunity() != null) {
- isClient.updateContextParam(id, CSUMMARY_ZENODOC, details.getMainZenodoCommunity(), true);
- }
-
- cc.updateCommunity(id, details);
- }
-
- public List getCommunityProjects(final String id) throws CommunityException, ResourceNotFoundException {
- cc.getCommunity(id); // ensure the community exists.
- 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(String id, CommunityProject project) throws CommunityException, ResourceNotFoundException {
- final TreeMap projects = getCommunityProjectMap(id);
- 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 addCommunityProjectList(final String id, final List 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");
- }
-
- List 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);
- }
-
- public void removeCommunityProject(final String id, final Integer projectId) throws CommunityException, ResourceNotFoundException {
- final Map 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 projectIdList) throws CommunityException, ResourceNotFoundException {
- for(Integer projectId: projectIdList){
- removeCommunityProject(id, projectId);
- }
- }
-
- public List 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(String id, CommunityContentprovider cp) throws CommunityException, ResourceNotFoundException {
- final TreeMap 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 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 addCommunityContentProvidersList(String id, List 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");
- }
-
- List contentproviders = new ArrayList();
-
- for(CommunityContentprovider contentProvider : contentprovidersList){
- contentproviders.add(updateContentprovider(id, contentProvider));
- }
-
-
- return contentproviders;
- }
-
- public void removeCommunityContentProviderList(final String id, final List contentProviderIdList) throws CommunityException, ResourceNotFoundException {
- for(Integer contentProviderId: contentProviderIdList){
- removeCommunityContentProvider(id, contentProviderId);
- }
- }
-
- public void removeCommunityOrganization(final String id, final Integer organizationId) throws CommunityException, ResourceNotFoundException {
- final Map 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 getCommunityZenodoCommunities(final String id) throws CommunityException, ResourceNotFoundException {
-
- return cc.getCommunityZenodoCommunities(id);
- }
-
- public List getCommunityOrganizations(final String id) throws CommunityException, ResourceNotFoundException {
- cc.getCommunity(id);
- return cc.getCommunityInfo(id, ORGANIZATION_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityOrganization(id, c));
- }
-
- public CommunityDetails addCommunitySubjects(final String id, final List subjects) throws CommunityException, ResourceNotFoundException {
-
- final CommunityDetails cd = new CommunityDetails();
-
- final Set current = Sets.newHashSet(cc.getCommunity(id).getSubjects());
-
- current.addAll(subjects);
-
- cd.setSubjects(Lists.newArrayList(current));
-
- setCommunity(id, CommunityWritableProperties.fromDetails(cd));
-
- return cd;
- }
-
- public CommunityDetails removeCommunitySubjects(final String id, final List subjects) throws CommunityException, ResourceNotFoundException {
-
- final CommunityDetails cd = new CommunityDetails();
-
- final Set current = Sets.newHashSet(cc.getCommunity(id).getSubjects());
-
- current.removeAll(subjects);
-
- cd.setSubjects(Lists.newArrayList(current));
-
- setCommunity(id, CommunityWritableProperties.fromDetails(cd));
-
- return cd;
- }
-
- public CommunityDetails addCommunityFOS(final String id, final List foss) throws CommunityException, ResourceNotFoundException {
-
- final CommunityDetails cd = new CommunityDetails();
-
- final Set 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 foss) throws CommunityException, ResourceNotFoundException {
-
- final CommunityDetails cd = new CommunityDetails();
-
- final Set 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 sdgs) throws CommunityException, ResourceNotFoundException {
-
- final CommunityDetails cd = new CommunityDetails();
- final Set 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 sdgs) throws CommunityException, ResourceNotFoundException {
-
- final CommunityDetails cd = new CommunityDetails();
-
- final Set 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, ResourceNotFoundException {
-
- final CommunityDetails cd = new CommunityDetails();
-
- cd.setAdvancedConstraints(advancedCosntraint);
-
- setCommunity(id, CommunityWritableProperties.fromDetails(cd));
-
- return cd;
- }
-
- public CommunityDetails removeCommunityAdvancedConstraint(final String id) throws ResourceNotFoundException, CommunityException {
-
- removeAdvancedConstraint(id);
-
- return new CommunityDetails();
- }
-
-
-
- @CacheEvict(value = "community-cache", allEntries = true)
- public void removeCommunityZenodoCommunity(final String id, final Integer zenodoCommId) throws CommunityException, ResourceNotFoundException {
-
- final Map zcomms = getZenodoCommunityMap(id);
- if (!zcomms.containsKey(zenodoCommId)) {
- throw new ResourceNotFoundException(String.format("Zenodo community '%s' doesn't exist within context '%s'", zenodoCommId, id));
- }
- isClient.removeConcept(id, id + ZENODOCOMMUNITY_ID_SUFFIX, id + ZENODOCOMMUNITY_ID_SUFFIX + ID_SEPARATOR + zenodoCommId);
-
- cc.removeFromCategory(id, ZENODOCOMMUNITY_ID_SUFFIX, String.valueOf(zenodoCommId));
-
- }
-
- @CacheEvict(value = "community-cache", allEntries = true)
- public CommunityZenodoCommunity addCommunityZenodoCommunity(final String id, final CommunityZenodoCommunity zc)
- throws CommunityException, ResourceNotFoundException {
- if (!StringUtils.equalsIgnoreCase(id, zc.getCommunityId())) { throw new CommunityException("parameters 'id' and zc.communityId must be coherent"); }
- if (!StringUtils.isNotBlank(zc.getZenodoid())) { throw new CommunityException("parameter zenodoid cannot be null or empty"); }
- final TreeMap zcs = getZenodoCommunityMap(id);
-
- for (final CommunityZenodoCommunity czc : zcs.values()) {
- if (czc.getZenodoid().equals(zc.getZenodoid())) { throw new CommunityException("Zenodo community already associated to the RCD"); }
- }
-
- zc.setId(nextId(!zcs.isEmpty() ? zcs.lastKey() : 0));
-
- isClient.addConcept(id, id + ZENODOCOMMUNITY_ID_SUFFIX, CommunityMappingUtils.asZenodoCommunityXML(id, zc));
- cc.updateZenodoCommunity(id, zc);
-
- return zc;
- }
-
- public CommunityOpenAIRECommunities getOpenAIRECommunities(final String zenodoId) throws CommunityException, ResourceNotFoundException {
-
- if (cci.getInverseZenodoCommunityMap().containsKey(zenodoId)) {
- return new CommunityOpenAIRECommunities().setZenodoid(zenodoId)
- .setOpenAirecommunitylist(cci.getInverseZenodoCommunityMap().get(zenodoId).stream().collect(Collectors.toList()));
- }
- return new CommunityOpenAIRECommunities();
-
- }
-
- // HELPERS
-
- private TreeMap 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 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 getZenodoCommunityMap(final String id) throws CommunityException, ResourceNotFoundException {
- return getCommunityZenodoCommunities(id).stream()
- .collect(Collectors.toMap(cp -> Integer.valueOf(cp.getId()), Functions.identity(), (cp1, cp2) -> {
- log.warn(String.format("duplicate Zenodo community found: '%s'", cp1.getId()));
- return cp2;
- }, TreeMap::new));
- }
-
- private TreeMap 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 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;
- }
-
-
-}
diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityClient.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityClient.java
deleted file mode 100644
index 4b028a20..00000000
--- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityClient.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package eu.dnetlib.openaire.community;
-
-import java.util.Map;
-import java.util.Set;
-
-import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
-import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
-
-public interface CommunityClient {
-
- Map> getInverseZenodoCommunityMap() throws CommunityException, ResourceNotFoundException;
-
- void dropCache();
-
-}
diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityClientImpl.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityClientImpl.java
deleted file mode 100644
index 06ff04f6..00000000
--- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityClientImpl.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package eu.dnetlib.openaire.community;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cache.annotation.CacheEvict;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Component;
-
-import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
-import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
-import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
-import eu.dnetlib.openaire.exporter.model.community.CommunityZenodoCommunity;
-
-import java.util.*;
-
-@Component
-public class CommunityClientImpl implements CommunityClient {
-
- private static final Log log = LogFactory.getLog(CommunityClient.class);
-
- @Autowired
- private CommunityCommon communityCommon;
-
- @Override
- @Cacheable("community-cache")
- public Map> getInverseZenodoCommunityMap () throws CommunityException, ResourceNotFoundException {
- log.info("Creating the data structure. Not using cache");
- final Map> inverseListMap = new HashMap<>();
-
- final List communityList = communityCommon.listCommunities();
-
- for(CommunitySummary cs :communityList){
- final String communityId = cs.getId();
- List czc = communityCommon.getCommunityZenodoCommunities(communityId);
- for(CommunityZenodoCommunity zc:czc){
- final String zenodoId = zc.getZenodoid();
- if(!inverseListMap.containsKey(zenodoId)) {
- inverseListMap.put(zc.getZenodoid(),new HashSet<>());
- }
- inverseListMap.get(zc.getZenodoid()).add(communityId);
- }
- final String zenodoMainCommunity = communityCommon.getCommunity(communityId).getZenodoCommunity();
- if(!inverseListMap.containsKey(zenodoMainCommunity)) {
- inverseListMap.put(zenodoMainCommunity,new HashSet<>());
- }
-
- inverseListMap.get(zenodoMainCommunity).add(communityId);
- }
- return inverseListMap;
- }
-
-
-
- @Override
- @CacheEvict(cacheNames = { "community-cache", "context-cache-community"}, allEntries = true)
- @Scheduled(fixedDelayString = "${openaire.exporter.cache.ttl}")
- public void dropCache(){
- log.debug("dropped community cache");
- }
-
-}
diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityCommon.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityCommon.java
deleted file mode 100644
index 1274e058..00000000
--- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityCommon.java
+++ /dev/null
@@ -1,489 +0,0 @@
-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.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;
-import eu.dnetlib.openaire.exporter.model.context.Category;
-import eu.dnetlib.openaire.exporter.model.context.Concept;
-import eu.dnetlib.openaire.exporter.model.context.Context;
-import eu.dnetlib.openaire.exporter.model.context.Param;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.io.IOException;
-import java.util.*;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-
-import static eu.dnetlib.openaire.community.CommunityConstants.*;
-
-
-@Component
-public class CommunityCommon {
-
- @Autowired
- private ISClient isClient;
-
- public Map getContextMap() throws CommunityException {
- try {
- return isClient.getCommunityContextMap();
- } catch (IOException e) {
- throw new CommunityException(e);
- }
- }
-
- public List listCommunities() throws CommunityException {
- return getContextMap().values().stream()
- .filter(context -> !communityBlackList.contains(context.getId()))
- .map(CommunityMappingUtils::asCommunitySummary)
- .collect(Collectors.toList());
- }
-
-
- public List getCommunityInfo(final String id, final String idSuffix, final Function mapping) throws CommunityException {
- final Map contextMap = getContextMap();
- final Context context = contextMap.get(id);
- if (context != null) {
- final Map categories = context.getCategories();
- final Category category = categories.get(id + idSuffix);
- if (category != null) {
- return category.getConcepts().stream()
- .map(mapping)
- .collect(Collectors.toList());
- }
- }
- return Lists.newArrayList();
- }
-
- public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException {
- final Context context = getContextMap().get(id);
- if (context == null || CommunityConstants.communityBlackList.contains(id)) {
- //ResponseStatusException(NOT_FOUND, "Unable to find resource");
- throw new ResourceNotFoundException();
- }
- return CommunityMappingUtils.asCommunityProfile(context);
- }
-
- public List getCommunityZenodoCommunities(final String id) throws CommunityException, ResourceNotFoundException {
- getCommunity(id); // ensure the community exists.
- return getCommunityInfo(id, ZENODOCOMMUNITY_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityZenodoCommunity(id, c));
- }
-
-
- public void updateProject(String communityId, CommunityProject project) throws CommunityException {
- final Context context = getContextMap().get(communityId);
- Category prj = context.getCategories().get(communityId + PROJECTS_ID_SUFFIX);
- if (prj.getConcepts().stream().map(c -> c.getId()).collect(Collectors.toList())
- .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{
- 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("");
-
- Map> 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(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);
-
- if(community.getShortName() != null) {
- context.setLabel(community.getShortName());
- }
-
- if (community.getName() != null){
- context.getParams().replace(CSUMMARY_NAME, Arrays.asList(new Param()
- .setValue(community.getName()).setName(CSUMMARY_NAME)));
- }
- if(community.getDescription() != null) {
- context.getParams()
- .replace(CSUMMARY_DESCRIPTION, Arrays.asList(new Param()
- .setName(CSUMMARY_DESCRIPTION).setValue(community.getDescription())));
- }
- if(community.getLogoUrl() != null){
- context.getParams()
- .replace(CSUMMARY_LOGOURL, Arrays.asList(new Param()
- .setName(CSUMMARY_LOGOURL).setValue(community.getLogoUrl())));
-
- }
- if (community.getStatus() != null) {
- context.getParams()
- .replace(CSUMMARY_STATUS, Arrays.asList(new Param()
- .setName(CSUMMARY_STATUS).setValue(community.getStatus().name())));
- }
- if (community.getSubjects() != null) {
- context.getParams()
- .replace(CPROFILE_SUBJECT, Arrays.asList(new Param().setName(CPROFILE_SUBJECT)
- .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.getAdvancedConstraints() != 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.getAdvancedConstraints()))));
- else
- context.getParams().put(CPROFILE_ADVANCED_CONSTRAINT, Arrays.asList(new Param()
- .setName(CPROFILE_ADVANCED_CONSTRAINT).setValue(new Gson().toJson(community.getAdvancedConstraints()))));
- }
- if(community.getMainZenodoCommunity() != null){
- context.getParams()
- .replace(CSUMMARY_ZENODOC, Arrays.asList(new Param()
- .setName(CSUMMARY_ZENODOC).setValue(community.getMainZenodoCommunity())));
-
- }
-
- }
-
-
- public void removeFromCategory(String communityId, String category, String conceptId) throws CommunityException {
- Map cmap = getContextMap();
- Context context = cmap.get(communityId);
- Map cat = context.getCategories();
-
- List concepts = cat.get(communityId + category).getConcepts()
- .stream().filter(c -> !c.getId().equals(communityId + category + ID_SEPARATOR + conceptId)).collect(Collectors.toList());
-
- cat.get(communityId + category).setConcepts(concepts);
- }
-
- public void updateDatasource(String communityId, CommunityContentprovider cp) throws CommunityException {
- final Context context = getContextMap().get(communityId);
- Category dts = context.getCategories().get(communityId + CONTENTPROVIDERS_ID_SUFFIX);
- if (dts.getConcepts().stream().map(c -> c.getId()).collect(Collectors.toList())
- .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{
- Concept concept = new Concept();
- concept.setId(communityId + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + cp.getId());
- concept.setClaim(false);
- concept.setLabel("");
-
- Map> 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(String communityId, CommunityOrganization organization) throws CommunityException {
-
- final Context context = getContextMap().get(communityId);
- Category orgs = context.getCategories().get(communityId + ORGANIZATION_ID_SUFFIX);
- if (orgs.getConcepts().stream().map(c -> c.getId()).collect(Collectors.toList())
- .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{
-
- Concept concept = new Concept();
- concept.setId(communityId + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organization.getId());
- concept.setClaim(false);
- concept.setLabel("");
-
- Map> 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(String communityId, CommunityZenodoCommunity zc) throws CommunityException {
- final Context context = getContextMap().get(communityId);
- Category zcs = context.getCategories().get(communityId + ZENODOCOMMUNITY_ID_SUFFIX);
- if (zcs.getConcepts().stream().map(c -> c.getId()).collect(Collectors.toList())
- .contains(communityId + ZENODOCOMMUNITY_ID_SUFFIX + ID_SEPARATOR + zc.getId())){
- zcs.getConcepts().forEach(concept -> {
- if (concept.getId().equals(communityId + ZENODOCOMMUNITY_ID_SUFFIX + ID_SEPARATOR + zc.getId())) {
-
-
- if (zc.getZenodoid() != null) {
- if(concept.getParams().keySet().contains(CZENODOCOMMUNITY_ID)){
- concept.getParams().replace(CZENODOCOMMUNITY_ID, Arrays.asList(new Param()
- .setName(CZENODOCOMMUNITY_ID).setValue(zc.getZenodoid())));
- }
- else{
- concept.getParams().put(CZENODOCOMMUNITY_ID, Arrays.asList(new Param()
- .setName(CZENODOCOMMUNITY_ID).setValue(zc.getZenodoid())));
- }
-
- }
-
- }
-
- });
- }
- else{
-
- Concept concept = new Concept();
- concept.setId(communityId + ZENODOCOMMUNITY_ID_SUFFIX + ID_SEPARATOR + zc.getId());
- concept.setClaim(false);
-
-
- Map> params = new TreeMap<>();
-
- if (zc.getZenodoid() != null) {
- params.put( CZENODOCOMMUNITY_ID, Arrays.asList(new Param().setValue(zc.getZenodoid()).setName(CZENODOCOMMUNITY_ID)));
- concept.setLabel(zc.getZenodoid());
- }else{
- concept.setLabel("");
- }
- concept.setParams(params);
- zcs.getConcepts().add(concept);
-
- }
-
- }
-
-}
diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityConstants.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityConstants.java
deleted file mode 100644
index 2bbd751e..00000000
--- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityConstants.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package eu.dnetlib.openaire.community;
-
-import java.util.Set;
-
-import com.google.common.collect.Sets;
-
-public class CommunityConstants {
-
- public final static Set communityBlackList = Sets.newHashSet("fet-fp7", "fet-h2020");
-
- // common
- public final static String OPENAIRE_ID = "openaireId";
- public final static String PIPE_SEPARATOR = "||";
- public final static String ID_SEPARATOR = "::";
- public final static String CSV_DELIMITER = ",";
- public final static String CLABEL = "label";
-
- // id suffixes
- public final static String PROJECTS_ID_SUFFIX = ID_SEPARATOR + "projects";
- public final static String CONTENTPROVIDERS_ID_SUFFIX = ID_SEPARATOR + "contentproviders";
- public final static String ZENODOCOMMUNITY_ID_SUFFIX = ID_SEPARATOR + "zenodocommunities";
- public final static String ORGANIZATION_ID_SUFFIX = ID_SEPARATOR + "organizations";
-
- // community summary
- public final static String CSUMMARY_DESCRIPTION = "description";
- public final static String CSUMMARY_LOGOURL = "logourl";
- public final static String CSUMMARY_STATUS = "status";
- public final static String CSUMMARY_NAME = "name";
- public final static String CSUMMARY_MANAGER = "manager";
- public final static String CSUMMARY_ZENODOC = "zenodoCommunity";
-
- // 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 = "advancedConstraints";
-
- // community project
- public final static String CPROJECT_FUNDER = "funder";
- public final static String CPROJECT_NUMBER = "CD_PROJECT_NUMBER";
- public final static String CPROJECT_FULLNAME = "projectfullname";
- public final static String CPROJECT_ACRONYM = "acronym";
-
- // community content provider
- public final static String CCONTENTPROVIDER_NAME = "name";
- public final static String CCONTENTPROVIDER_OFFICIALNAME = "officialname";
- public final static String CCONTENTPROVIDER_ENABLED = "enabled";
- public final static String CCONTENTPROVIDERENABLED_DEFAULT = "true";
- public final static String CCONTENTPROVIDER_SELCRITERIA = "selcriteria";
-
- //community zenodo community
- public final static String CZENODOCOMMUNITY_ID = "zenodoid";
-
- //community organization
- public final static String CORGANIZATION_NAME = "name";
- public final static String CORGANIZATION_LOGOURL = "logourl";
- public final static String CORGANIZATION_WEBSITEURL = "websiteurl";
-
-
-}
diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityMappingUtils.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityMappingUtils.java
deleted file mode 100644
index fb5da147..00000000
--- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityMappingUtils.java
+++ /dev/null
@@ -1,251 +0,0 @@
-package eu.dnetlib.openaire.community;
-
-import java.text.ParseException;
-import java.util.*;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import com.google.common.escape.Escaper;
-import com.google.common.xml.XmlEscapers;
-
-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.CommunityStatus;
-import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
-import eu.dnetlib.openaire.exporter.model.community.CommunityZenodoCommunity;
-import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionCriteria;
-import eu.dnetlib.openaire.exporter.model.context.Concept;
-import eu.dnetlib.openaire.exporter.model.context.Context;
-import eu.dnetlib.openaire.exporter.model.context.Param;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import static eu.dnetlib.openaire.common.Utils.escape;
-import static eu.dnetlib.openaire.community.CommunityConstants.*;
-
-public class CommunityMappingUtils {
-
- private final static String pattern = "yyyy-MM-dd'T'hh:mm:ss";
-
- private static final Log log = LogFactory.getLog(CommunityMappingUtils.class);
-
- public static CommunitySummary asCommunitySummary(final Context c) {
- final CommunitySummary summary = new CommunitySummary();
-
- summary.setId(c.getId());
- summary.setShortName(c.getLabel());
- summary.setLastUpdateDate(c.getLastUpdateDate());
- summary.setCreationDate(c.getCreationDate());
- summary.setQueryId(c.getId() + PIPE_SEPARATOR + c.getLabel());
- summary.setType(c.getType());
-
- final Map> params = c.getParams();
- if (params.containsKey(CSUMMARY_DESCRIPTION)) {
- summary.setDescription(asCsv(params.get(CSUMMARY_DESCRIPTION)));
- }
- if (params.containsKey(CSUMMARY_LOGOURL)) {
- summary.setLogoUrl(asCsv(params.get(CSUMMARY_LOGOURL)));
- }
- if (params.containsKey(CSUMMARY_STATUS)) {
- summary.setStatus(CommunityStatus.valueOf(firstValue(params, CSUMMARY_STATUS)));
- }
- if (params.containsKey(CSUMMARY_NAME)) {
- summary.setName(asCsv(params.get(CSUMMARY_NAME)));
- }
- if (params.containsKey(CSUMMARY_ZENODOC)) {
- summary.setZenodoCommunity(asCsv(params.get(CSUMMARY_ZENODOC)));
- }
-
- return summary;
- }
-
- public static CommunityDetails asCommunityProfile(final Context c) {
-
- final CommunityDetails p = new CommunityDetails(asCommunitySummary(c));
- p.setLastUpdateDate(c.getLastUpdateDate());
- final Map> params = c.getParams();
- 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)) {
- //In the map the string is the serialization of the json representing the selection criteria so it is a valid json
- p.setAdvancedConstraints(SelectionCriteria.fromJson(asCsv(params.get(CPROFILE_ADVANCED_CONSTRAINT))));
-
- }
- if (params.containsKey(CPROFILE_CREATIONDATE)){
- try {
- p.setCreationDate(org.apache.commons.lang3.time.DateUtils.parseDate(asCsv(params.get(CPROFILE_CREATIONDATE)), pattern));
- }catch(ParseException e) {
- log.debug("Exception on date format: " + e.getMessage());
- }
- }
-
- return p;
- }
-
- public static CommunityProject asCommunityProject(final String communityId, final Concept c) {
-
- final Map> p = c.getParams();
- final CommunityProject project = new CommunityProject();
- project.setCommunityId(communityId);
- 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));
- project.setName(firstValue(p, CPROJECT_FULLNAME));
- project.setAcronym(firstValue(p, CPROJECT_ACRONYM));
-
- return project;
- }
-
- public static CommunityContentprovider asCommunityDataprovider(final String communityId, final Concept c) {
-
- final Map> p = c.getParams();
- final CommunityContentprovider d = new CommunityContentprovider();
- d.setCommunityId(communityId);
- 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));
- d.setSelectioncriteria(SelectionCriteria.fromJson(firstValue(p, CCONTENTPROVIDER_SELCRITERIA)));
- return d;
- }
-
- public static CommunityZenodoCommunity asCommunityZenodoCommunity(final String communityId, final Concept c){
- final CommunityZenodoCommunity z = new CommunityZenodoCommunity();
- final Map> p = c.getParams();
- z.setCommunityId(communityId);
- z.setId(StringUtils.substringAfterLast(c.getId(), ID_SEPARATOR));
- z.setZenodoid(firstValue(p,CZENODOCOMMUNITY_ID));
- //z.setName(c.getLabel());
- return z;
- }
-
-
- public static CommunityOrganization asCommunityOrganization(String id, Concept c) {
- final Map> p = c.getParams();
- final CommunityOrganization o = new CommunityOrganization();
- o.setCommunityId(id);
- o.setId(StringUtils.substringAfterLast(c.getId(), ID_SEPARATOR));
- o.setName(firstValue(p,CORGANIZATION_NAME));
- o.setLogo_url(getDecodedUrl(firstValue(p,CORGANIZATION_LOGOURL)));
- o.setWebsite_url(getDecodedUrl(firstValue(p,CORGANIZATION_WEBSITEURL)));
-
- return o;
- }
-
- private static String getDecodedUrl(final String encoded_url){
- if(encoded_url == null){
- return encoded_url;
- }
- return new String(Base64.getDecoder().decode(encoded_url));
- }
-
-
- private static List splitValues(final Stream stream, final String separator) {
- return stream.map(s -> s.split(separator))
- .map(Arrays::asList)
- .flatMap(List::stream)
- .filter(StringUtils::isNotBlank)
- .map(StringUtils::trim)
- .collect(Collectors.toList());
- }
-
- private static String firstValue(final Map> p, final String paramName) {
- return asValues(p.get(paramName)).findFirst().orElse(null);
- }
-
- private static String asCsv(final List params) {
- return asValues(params)
- .collect(Collectors.joining(CSV_DELIMITER));
- }
-
- private static Stream asValues(final List params) {
- return params == null ? Stream.empty() : params.stream()
- .map(Param::getValue)
- .map(StringUtils::trim)
- .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(
- "\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("\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(
- "\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("\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();
- sb.append(
- String.format(
- "\n",
- escape(esc, contextId), ZENODOCOMMUNITY_ID_SUFFIX, ID_SEPARATOR, escape(esc, String.valueOf(zc.getId())), escape(esc, zc.getZenodoid())));
-
- sb.append(paramXML(CZENODOCOMMUNITY_ID, zc.getZenodoid()));
- sb.append("\n");
- return sb.toString();
- }
-
-
- public static String asOrganizationXML(final String contextId, CommunityOrganization organization) {
- final Escaper esc = XmlEscapers.xmlAttributeEscaper();
- final StringBuilder sb = new StringBuilder();
- sb.append(
- String.format(
- "\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("\n");
- return sb.toString();
- }
-
-
- private static String paramXML(final String paramName, final String value) {
- return String.format("%s\n", paramName, escape(XmlEscapers.xmlContentEscaper(), value));
- }
-
- private static String paramXMLNoEscape(final String paramName, final String value) {
- return String.format("%s\n", paramName, value);
- }
-
-}
diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityService.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityService.java
new file mode 100644
index 00000000..defe39d1
--- /dev/null
+++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityService.java
@@ -0,0 +1,472 @@
+package eu.dnetlib.openaire.community;
+
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import javax.persistence.criteria.Predicate;
+import javax.transaction.Transactional;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+
+import eu.dnetlib.openaire.community.model.DbCommunity;
+import eu.dnetlib.openaire.community.model.DbDatasource;
+import eu.dnetlib.openaire.community.model.DbDatasourcePK;
+import eu.dnetlib.openaire.community.model.DbOrganization;
+import eu.dnetlib.openaire.community.model.DbProject;
+import eu.dnetlib.openaire.community.model.DbProjectPK;
+import eu.dnetlib.openaire.community.model.DbSubCommunity;
+import eu.dnetlib.openaire.community.model.DbSupportOrg;
+import eu.dnetlib.openaire.community.model.DbSupportOrgPK;
+import eu.dnetlib.openaire.community.repository.DbCommunityRepository;
+import eu.dnetlib.openaire.community.repository.DbDatasourceRepository;
+import eu.dnetlib.openaire.community.repository.DbOrganizationRepository;
+import eu.dnetlib.openaire.community.repository.DbProjectRepository;
+import eu.dnetlib.openaire.community.repository.DbSubCommunityRepository;
+import eu.dnetlib.openaire.community.repository.DbSupportOrgRepository;
+import eu.dnetlib.openaire.community.utils.CommunityMappingUtils;
+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.SubCommunity;
+import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionCriteria;
+import eu.dnetlib.openaire.exporter.model.context.IISConfigurationEntry;
+
+@Service
+@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
+public class CommunityService {
+
+ @Autowired
+ private DbCommunityRepository dbCommunityRepository;
+ @Autowired
+ private DbProjectRepository dbProjectRepository;
+ @Autowired
+ private DbDatasourceRepository dbDatasourceRepository;
+ @Autowired
+ private DbOrganizationRepository dbOrganizationRepository;
+ @Autowired
+ private DbSupportOrgRepository dbSupportOrgRepository;
+ @Autowired
+ private DbSubCommunityRepository dbSubCommunityRepository;
+
+ private static final Log log = LogFactory.getLog(CommunityService.class);
+
+ public List listCommunities() {
+ return dbCommunityRepository.findAll()
+ .stream()
+ .map(CommunityMappingUtils::toCommunitySummary)
+ .collect(Collectors.toList());
+ }
+
+ @Transactional
+ public CommunityDetails newCommunity(final CommunityDetails details) throws CommunityException {
+ if (StringUtils.isBlank(details.getId())) {
+ throw new CommunityException("Empty Id");
+ } else if (dbCommunityRepository.existsById(details.getId())) {
+ throw new CommunityException("Community already exists: " + details.getId());
+ } else {
+ details.setCreationDate(LocalDateTime.now());
+ return saveCommunity(details);
+ }
+
+ }
+
+ @Transactional
+ public CommunityDetails saveCommunity(final CommunityDetails details) {
+ details.setLastUpdateDate(LocalDateTime.now());
+ dbCommunityRepository.save(CommunityMappingUtils.toCommunity(details));
+ return getCommunity(details.getId());
+ }
+
+ @Transactional
+ public CommunityDetails getCommunity(final String id) {
+ final DbCommunity c = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
+ return CommunityMappingUtils.toCommunityDetails(c);
+ }
+
+ @Transactional
+ public void setCommunity(final String id, final CommunityWritableProperties details) {
+ final DbCommunity c = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
+ CommunityMappingUtils.populateCommunity(c, details);
+ c.setLastUpdateDate(LocalDateTime.now());
+ dbCommunityRepository.save(c);
+ }
+
+ @Transactional
+ public Page getCommunityProjects(final String id,
+ final String funder,
+ final String filter,
+ final int page,
+ final int size,
+ final String orderBy) throws CommunityException {
+ if (StringUtils.isBlank(id)) { throw new CommunityException("Empty ID"); }
+ try {
+ final Sort sort;
+ if (StringUtils.isBlank(orderBy)) {
+ sort = Sort.by("projectName");
+ } else if (orderBy.equalsIgnoreCase("funder")) {
+ sort = Sort.by("projectFunder").and(Sort.by("projectName"));
+ } else if (orderBy.equalsIgnoreCase("grantId")) {
+ sort = Sort.by("projectCode");
+ } else if (orderBy.equalsIgnoreCase("acronym")) {
+ sort = Sort.by("projectAcronym");
+ } else if (orderBy.equalsIgnoreCase("openaireId")) {
+ sort = Sort.by("projectId");
+ } else {
+ sort = Sort.by("projectName");
+ }
+
+ final PageRequest pageable = PageRequest.of(page, size, sort);
+ if (StringUtils.isAllBlank(filter, funder)) {
+ return dbProjectRepository.findByCommunity(id, pageable).map(CommunityMappingUtils::toCommunityProject);
+ } else {
+ final Specification projSpec = prepareProjectSpec(id, funder, filter);
+ return dbProjectRepository.findAll(projSpec, pageable).map(CommunityMappingUtils::toCommunityProject);
+ }
+ } catch (final Throwable e) {
+ log.error(e);
+ throw new CommunityException(e);
+ }
+ }
+
+ private Specification prepareProjectSpec(final String community, final String funder, final String other) {
+ return (project, query, cb) -> {
+
+ final List andConds = new ArrayList<>();
+ andConds.add(cb.equal(project.get("community"), community));
+
+ if (StringUtils.isNotBlank(funder)) {
+ andConds.add(cb.equal(project.get("projectFunder"), funder));
+ }
+
+ if (StringUtils.isNotBlank(other)) {
+ final String s = other.toLowerCase().trim();
+
+ final List orConds = new ArrayList<>();
+ orConds.add(cb.equal(cb.lower(project.get("projectId")), s));
+ orConds.add(cb.equal(cb.lower(project.get("projectCode")), s));
+ orConds.add(cb.equal(cb.lower(project.get("projectAcronym")), s));
+ orConds.add(cb.like(cb.lower(project.get("projectName")), "%" + s + "%"));
+ if (StringUtils.isBlank(funder)) {
+ orConds.add(cb.equal(cb.lower(project.get("projectFunder")), s));
+ }
+
+ andConds.add(cb.or(orConds.toArray(new Predicate[orConds.size()])));
+ }
+
+ return cb.and(andConds.toArray(new Predicate[andConds.size()]));
+ };
+
+ }
+
+ @Transactional
+ public CommunityProject addCommunityProject(final String id, final CommunityProject project) {
+ final DbProject p = CommunityMappingUtils.toDbProject(id, project);
+ dbProjectRepository.save(p);
+ return project;
+ }
+
+ @Transactional
+ public void addCommunityProjects(final String id, final CommunityProject... projects) throws CommunityException {
+ try {
+ final List list = Arrays.stream(projects)
+ .map(p -> CommunityMappingUtils.toDbProject(id, p))
+ .collect(Collectors.toList());
+
+ dbProjectRepository.saveAll(list);
+ } catch (final Throwable e) {
+ log.error(e);
+ throw new CommunityException(e);
+ }
+ }
+
+ @Transactional
+ public void removeCommunityProjects(final String id, final String... ids) {
+ final List list = Arrays.stream(ids)
+ .map(projectId -> new DbProjectPK(id, projectId))
+ .collect(Collectors.toList());
+ dbProjectRepository.deleteAllById(list);
+ }
+
+ public List getCommunityContentproviders(final String id) {
+ return dbDatasourceRepository.findByCommunity(id)
+ .stream()
+ .map(CommunityMappingUtils::toCommunityContentprovider)
+ .collect(Collectors.toList());
+ }
+
+ @Transactional
+ public void addCommunityContentProviders(final String id, final CommunityContentprovider... contentproviders) {
+ final List list = Arrays.stream(contentproviders)
+ .map(cp -> CommunityMappingUtils.toDbDatasource(id, cp))
+ .collect(Collectors.toList());
+
+ dbDatasourceRepository.saveAll(list);
+ }
+
+ @Transactional
+ public void removeCommunityContentProviders(final String id, final String... ids) {
+ final List list = Arrays.stream(ids)
+ .map(dsId -> new DbDatasourcePK(id, dsId))
+ .collect(Collectors.toList());
+ dbDatasourceRepository.deleteAllById(list);
+ }
+
+ @Transactional
+ public void removeCommunityOrganizations(final String id, final String... orgNames) {
+ final List list = Arrays.stream(orgNames)
+ .map(name -> new DbSupportOrgPK(id, name))
+ .collect(Collectors.toList());
+ dbSupportOrgRepository.deleteAllById(list);
+ }
+
+ @Transactional
+ public List getCommunityOrganizations(final String id) {
+ return dbSupportOrgRepository.findByCommunity(id)
+ .stream()
+ .map(CommunityMappingUtils::toCommunityOrganization)
+ .collect(Collectors.toList());
+ }
+
+ @Transactional
+ public void addCommunityOrganizations(final String id, final CommunityOrganization... orgs) {
+ final List list = Arrays.stream(orgs)
+ .map(o -> CommunityMappingUtils.toDbSupportOrg(id, o))
+ .collect(Collectors.toList());
+
+ dbSupportOrgRepository.saveAll(list);
+ }
+
+ @Transactional
+ public void removeSubCommunities(final String id, final String... subCommunityIds) {
+ dbSubCommunityRepository.deleteAllById(Arrays.asList(subCommunityIds));
+ }
+
+ @Transactional
+ public List getSubCommunities(final String id) {
+ return dbSubCommunityRepository.findByCommunity(id)
+ .stream()
+ .map(CommunityMappingUtils::toSubCommunity)
+ .collect(Collectors.toList());
+ }
+
+ @Transactional
+ public void addSubCommunities(final String id, final SubCommunity... subs) {
+ final List list = Arrays.stream(subs)
+ .map(s -> CommunityMappingUtils.toDbSubCommunity(id, s))
+ .collect(Collectors.toList());
+
+ dbSubCommunityRepository.saveAll(list);
+ }
+
+ @Transactional
+ public CommunityDetails addCommunitySubjects(final String id, final String... subjects) {
+ return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), false, subjects);
+ }
+
+ public CommunityDetails removeCommunitySubjects(final String id, final String... subjects) {
+ return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), true, subjects);
+ }
+
+ public CommunityDetails addCommunityFOS(final String id, final String... foss) {
+ return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), false, foss);
+ }
+
+ public CommunityDetails removeCommunityFOS(final String id, final String... foss) {
+ return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), true, foss);
+ }
+
+ public CommunityDetails addCommunitySDG(final String id, final String... sdgs) {
+ return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), false, sdgs);
+ }
+
+ public CommunityDetails removeCommunitySDG(final String id, final String... sdgs) {
+ return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), true, sdgs);
+ }
+
+ @Transactional
+ public CommunityDetails addCommunityAdvancedConstraint(final String id, final SelectionCriteria advancedCosntraint) {
+ final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
+ dbEntry.setAdvancedConstraints(advancedCosntraint);
+ dbEntry.setLastUpdateDate(LocalDateTime.now());
+ dbCommunityRepository.save(dbEntry);
+ return getCommunity(id);
+ }
+
+ @Transactional
+ public CommunityDetails removeCommunityAdvancedConstraint(final String id) {
+ final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
+ dbEntry.setAdvancedConstraints(null);
+ dbEntry.setLastUpdateDate(LocalDateTime.now());
+ dbCommunityRepository.save(dbEntry);
+ return getCommunity(id);
+ }
+
+ @Transactional
+ public CommunityDetails addCommunityRemoveConstraint(final String id, final SelectionCriteria removeConstraint) {
+ final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
+ dbEntry.setRemoveConstraints(removeConstraint);
+ dbEntry.setLastUpdateDate(LocalDateTime.now());
+ dbCommunityRepository.save(dbEntry);
+ return getCommunity(id);
+ }
+
+ @Transactional
+ public CommunityDetails removeCommunityRemoveConstraint(final String id) {
+ final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
+ dbEntry.setRemoveConstraints(null);
+ dbEntry.setLastUpdateDate(LocalDateTime.now());
+ dbCommunityRepository.save(dbEntry);
+ return getCommunity(id);
+ }
+
+ public CommunityDetails removeCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain) {
+ if (isMain) {
+ return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), null);
+ } else {
+ return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), true, zenodoCommunity);
+ }
+ }
+
+ public CommunityDetails addCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain) {
+ if (isMain) {
+ return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), zenodoCommunity);
+ } else {
+ return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), false, zenodoCommunity);
+ }
+ }
+
+ @Transactional
+ private CommunityDetails updateElementToSimpleField(final String id,
+ final BiConsumer setter,
+ final String value) {
+ final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
+ setter.accept(dbEntry, value);
+ dbEntry.setLastUpdateDate(LocalDateTime.now());
+ dbCommunityRepository.save(dbEntry);
+ return getCommunity(id);
+ }
+
+ @Transactional
+ private CommunityDetails modifyElementToArrayField(final String id,
+ final Function getter,
+ final BiConsumer setter,
+ final boolean remove,
+ final String... values) {
+
+ final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
+
+ final Set tmpList = new LinkedHashSet<>();
+ final String[] oldValues = getter.apply(dbEntry);
+ if (oldValues != null) {
+ for (final String s : oldValues) {
+ tmpList.add(s);
+ }
+ }
+ if (remove) {
+ tmpList.removeAll(Arrays.asList(values));
+ } else {
+ tmpList.addAll(Arrays.asList(values));
+ }
+
+ setter.accept(dbEntry, tmpList.toArray(new String[tmpList.size()]));
+
+ dbEntry.setLastUpdateDate(LocalDateTime.now());
+
+ dbCommunityRepository.save(dbEntry);
+
+ return getCommunity(id);
+ }
+
+ @Transactional
+ public List getOpenAIRECommunitiesByZenodoId(final String zenodoId) {
+ return dbCommunityRepository.findByZenodoId(zenodoId);
+ }
+
+ @Transactional
+ public Map> getPropagationOrganizationCommunityMap() {
+ return dbOrganizationRepository.findAll()
+ .stream()
+ .collect(Collectors.groupingBy(DbOrganization::getOrgId, Collectors.mapping(DbOrganization::getCommunity, Collectors.toSet())));
+ }
+
+ @Transactional
+ public Set getPropagationOrganizationsForCommunity(final String communityId) {
+ return dbOrganizationRepository.findByCommunity(communityId)
+ .stream()
+ .map(DbOrganization::getOrgId)
+ .collect(Collectors.toSet());
+ }
+
+ @Transactional
+ public Set addPropagationOrganizationForCommunity(final String communityId, final String... organizationIds) {
+ for (final String orgId : organizationIds) {
+ final DbOrganization o = new DbOrganization(communityId.trim(), orgId.trim());
+ dbOrganizationRepository.save(o);
+ }
+ return getPropagationOrganizationsForCommunity(communityId);
+ }
+
+ @Transactional
+ public Set removePropagationOrganizationForCommunity(final String communityId, final String... organizationIds) {
+ for (final String orgId : organizationIds) {
+ final DbOrganization o = new DbOrganization(communityId.trim(), orgId.trim());
+ dbOrganizationRepository.delete(o);
+ }
+ return getPropagationOrganizationsForCommunity(communityId);
+ }
+
+ @Transactional
+ public void deleteCommunity(final String id, final boolean recursive) {
+ if (recursive) {
+ dbProjectRepository.deleteByCommunity(id);
+ dbDatasourceRepository.deleteByCommunity(id);
+ dbOrganizationRepository.deleteByCommunity(id);
+ dbSupportOrgRepository.deleteByCommunity(id);
+ dbSubCommunityRepository.deleteByCommunity(id);
+ }
+ dbCommunityRepository.deleteById(id);
+ }
+
+ @Transactional
+ public List getIISConfiguration(final String id) {
+ final List res = new ArrayList<>();
+
+ res.add(dbCommunityRepository.findById(id)
+ .map(CommunityMappingUtils::asIISConfigurationEntry)
+ .orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id)));
+
+ for (final DbSubCommunity subc : dbSubCommunityRepository.findByCommunity(id)) {
+ res.add(CommunityMappingUtils.asIISConfigurationEntry(subc));
+ }
+
+ return res;
+ }
+
+ @Transactional
+ public List getCommunityFunders(final String id) {
+ return dbProjectRepository.findFundersByCommunity(id);
+ }
+
+}
diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterController.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterController.java
new file mode 100644
index 00000000..3f7cefb6
--- /dev/null
+++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterController.java
@@ -0,0 +1,87 @@
+package eu.dnetlib.openaire.community.importer;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.google.common.collect.Sets;
+
+import eu.dnetlib.common.controller.AbstractDnetController;
+import eu.dnetlib.openaire.common.ISClient;
+import eu.dnetlib.openaire.community.model.DbOrganization;
+import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
+import eu.dnetlib.openaire.exporter.model.context.Context;
+import io.swagger.v3.oas.annotations.tags.Tag;
+
+@RestController
+@CrossOrigin(origins = {
+ "*"
+})
+@ConditionalOnProperty(value = "openaire.exporter.enable.community.import", havingValue = "true")
+@Tag(name = "OpenAIRE Communities: Migration API", description = "OpenAIRE Communities: Migration API")
+public class CommunityImporterController extends AbstractDnetController {
+
+ // public final static Set communityBlackList = Sets.newHashSet("fet-fp7", "fet-h2020");
+ public final static Set communityBlackList = Sets.newHashSet();
+
+ @Autowired
+ private CommunityImporterService importer;
+
+ @Autowired
+ private ISClient isClient;
+
+ private static final Log log = LogFactory.getLog(CommunityImporterController.class);
+
+ @GetMapping("/community_importer/communities")
+ public List importProfiles() throws CommunityException {
+ try {
+ final Map contextMap = getContextMap();
+
+ final List list = contextMap.keySet()
+ .stream()
+ .filter(id -> !communityBlackList.contains(id))
+ .collect(Collectors.toList());
+
+ list.forEach(id -> {
+ importer.importCommunity(contextMap.get(id));
+ });
+
+ return list;
+ } catch (final Throwable e) {
+ log.error("Error importing communities", e);
+ throw new CommunityException(e.getMessage());
+ }
+ }
+
+ @GetMapping("/community_importer/propagationOrgs")
+ public List importPropagationOrgs(@RequestParam final String profileId,
+ @RequestParam(required = false, defaultValue = "false") final boolean simulation) throws Exception {
+ try {
+ final String xml = isClient.getProfile(profileId);
+ return importer.importPropagationOrganizationsFromProfile(xml, simulation);
+ } catch (final Throwable e) {
+ log.error("Error importing communities", e);
+ throw new CommunityException(e.getMessage());
+ }
+ }
+
+ private Map getContextMap() throws CommunityException {
+ try {
+ return isClient.getCommunityContextMap();
+ } catch (final IOException e) {
+ throw new CommunityException(e);
+ }
+ }
+
+}
diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterService.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterService.java
new file mode 100644
index 00000000..224beee9
--- /dev/null
+++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterService.java
@@ -0,0 +1,407 @@
+package eu.dnetlib.openaire.community.importer;
+
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import javax.transaction.Transactional;
+
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.dom4j.DocumentHelper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.Lists;
+
+import eu.dnetlib.miscutils.functional.hash.Hashing;
+import eu.dnetlib.openaire.community.CommunityService;
+import eu.dnetlib.openaire.community.model.DbOrganization;
+import eu.dnetlib.openaire.community.repository.DbOrganizationRepository;
+import eu.dnetlib.openaire.community.utils.CommunityMappingUtils;
+import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
+import eu.dnetlib.openaire.exporter.model.community.CommunityClaimType;
+import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
+import eu.dnetlib.openaire.exporter.model.community.CommunityDetails;
+import eu.dnetlib.openaire.exporter.model.community.CommunityMembershipType;
+import eu.dnetlib.openaire.exporter.model.community.CommunityOrganization;
+import eu.dnetlib.openaire.exporter.model.community.CommunityProject;
+import eu.dnetlib.openaire.exporter.model.community.CommunityStatus;
+import eu.dnetlib.openaire.exporter.model.community.CommunityType;
+import eu.dnetlib.openaire.exporter.model.community.SubCommunity;
+import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionCriteria;
+import eu.dnetlib.openaire.exporter.model.context.Category;
+import eu.dnetlib.openaire.exporter.model.context.Concept;
+import eu.dnetlib.openaire.exporter.model.context.Context;
+import eu.dnetlib.openaire.exporter.model.context.Param;
+
+@Service
+@ConditionalOnProperty(value = "openaire.exporter.enable.community.import", havingValue = "true")
+public class CommunityImporterService {
+
+ // common
+ public final static String OPENAIRE_ID = "openaireId";
+ public final static String PIPE_SEPARATOR = "||";
+ public final static String ID_SEPARATOR = "::";
+ public final static String CSV_DELIMITER = ",";
+ public final static String CLABEL = "label";
+
+ // id suffixes
+ public final static String PROJECTS_ID_SUFFIX = ID_SEPARATOR + "projects";
+ public final static String CONTENTPROVIDERS_ID_SUFFIX = ID_SEPARATOR + "contentproviders";
+ public final static String ZENODOCOMMUNITY_ID_SUFFIX = ID_SEPARATOR + "zenodocommunities";
+ public final static String ORGANIZATION_ID_SUFFIX = ID_SEPARATOR + "organizations";
+
+ // community summary
+ public final static String CSUMMARY_DESCRIPTION = "description";
+ public final static String CSUMMARY_LOGOURL = "logourl";
+ public final static String CSUMMARY_STATUS = "status";
+ public final static String CSUMMARY_NAME = "name";
+ public final static String CSUMMARY_MANAGER = "manager";
+ public final static String CSUMMARY_ZENODOC = "zenodoCommunity";
+
+ // 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 = "advancedConstraints";
+ public final static String CPROFILE_REMOVE_CONSTRAINT = "removeConstraints";
+ public final static String CPROFILE_SUGGESTED_ACKNOWLEDGEMENT = "suggestedAcknowledgement";
+
+ // community project
+ public final static String CPROJECT_FUNDER = "funder";
+ public final static String CPROJECT_NUMBER = "CD_PROJECT_NUMBER";
+ public final static String CPROJECT_FULLNAME = "projectfullname";
+ public final static String CPROJECT_ACRONYM = "acronym";
+
+ // community content provider
+ public final static String CCONTENTPROVIDER_NAME = "name";
+ public final static String CCONTENTPROVIDER_OFFICIALNAME = "officialname";
+ public final static String CCONTENTPROVIDER_ENABLED = "enabled";
+ public final static String CCONTENTPROVIDERENABLED_DEFAULT = "true";
+ public final static String CCONTENTPROVIDER_SELCRITERIA = "selcriteria";
+
+ // community zenodo community
+ public final static String CZENODOCOMMUNITY_ID = "zenodoid";
+
+ // community organization
+ public final static String CORGANIZATION_NAME = "name";
+ public final static String CORGANIZATION_LOGOURL = "logourl";
+ public final static String CORGANIZATION_WEBSITEURL = "websiteurl";
+
+ @Autowired
+ private DbOrganizationRepository dbOrganizationRepository;
+
+ @Autowired
+ private CommunityService service;
+
+ @Autowired
+ private JdbcTemplate jdbcTemplate;
+
+ private static final Log log = LogFactory.getLog(CommunityImporterService.class);
+
+ public List importPropagationOrganizationsFromProfile(final String xml, final boolean simulation) throws Exception {
+ final String json = DocumentHelper.parseText(xml)
+ .selectSingleNode("//NODE[@name='setPropagationOrganizationCommunityMap']//PARAM[@name='parameterValue']")
+ .getText();
+
+ final List list = new ObjectMapper()
+ .readValue(json, new TypeReference