new_model_for_communities #15
|
@ -141,6 +141,12 @@
|
||||||
<artifactId>spring-web</artifactId>
|
<artifactId>spring-web</artifactId>
|
||||||
<version>5.3.8</version>
|
<version>5.3.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.vladmihalcea</groupId>
|
||||||
|
<artifactId>hibernate-types-52</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -16,7 +16,9 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
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.DsmApiException;
|
||||||
|
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
|
||||||
import eu.dnetlib.openaire.exporter.model.dsm.Response;
|
import eu.dnetlib.openaire.exporter.model.dsm.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,17 +30,26 @@ public abstract class AbstractExporterController {
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ExceptionHandler({
|
@ExceptionHandler({
|
||||||
DsmApiException.class
|
DsmApiException.class, CommunityException.class, Exception.class
|
||||||
})
|
})
|
||||||
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
@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);
|
return _handleError(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
public List<ErrorMessage> processValidationError(final MethodArgumentNotValidException e) {
|
public List<ErrorMessage> handle400(final MethodArgumentNotValidException e) {
|
||||||
return e.getBindingResult()
|
return e.getBindingResult()
|
||||||
.getFieldErrors()
|
.getFieldErrors()
|
||||||
.stream()
|
.stream()
|
||||||
|
|
|
@ -10,6 +10,7 @@ public class ExporterConstants {
|
||||||
public final static String C_PJ = "Community projects";
|
public final static String C_PJ = "Community projects";
|
||||||
public final static String C_ZC = "Community Zenodo Communities";
|
public final static String C_ZC = "Community Zenodo Communities";
|
||||||
public final static String C_O = "Community Organizations";
|
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 DS = "Datasource";
|
||||||
public final static String API = "Interface";
|
public final static String API = "Interface";
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
||||||
import eu.dnetlib.openaire.dsm.dao.utils.IndexDsInfo;
|
import eu.dnetlib.openaire.dsm.dao.utils.IndexDsInfo;
|
||||||
import eu.dnetlib.openaire.exporter.model.context.Context;
|
import eu.dnetlib.openaire.exporter.model.context.Context;
|
||||||
|
|
||||||
|
@ -13,18 +14,25 @@ public interface ISClient {
|
||||||
|
|
||||||
String getObjectStoreId(String dsId) throws Exception;
|
String getObjectStoreId(String dsId) throws Exception;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
Map<String, Context> getFunderContextMap() throws IOException;
|
Map<String, Context> getFunderContextMap() throws IOException;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
Map<String, Context> getCommunityContextMap() throws IOException;
|
Map<String, Context> getCommunityContextMap() throws IOException;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
Map<String, Context> getContextMap(final List<String> type) throws IOException;
|
Map<String, Context> getContextMap(final List<String> type) throws IOException;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
void updateContextParam(String id, String name, String value, boolean toEscape);
|
void updateContextParam(String id, String name, String value, boolean toEscape);
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
void updateContextAttribute(String id, String name, String value);
|
void updateContextAttribute(String id, String name, String value);
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
void addConcept(String id, String categoryId, String data);
|
void addConcept(String id, String categoryId, String data);
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
void removeConcept(String id, String categoryId, String conceptId);
|
void removeConcept(String id, String categoryId, String conceptId);
|
||||||
|
|
||||||
void dropCache();
|
void dropCache();
|
||||||
|
@ -38,10 +46,15 @@ public interface ISClient {
|
||||||
* @param value
|
* @param value
|
||||||
* new value for the attribute
|
* new value for the attribute
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
void updateConceptAttribute(String id, String name, String value);
|
void updateConceptAttribute(String id, String name, String value);
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
void updateConceptParam(String id, String name, String value);
|
void updateConceptParam(String id, String name, String value);
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
void updateConceptParamNoEscape(String id, String name, String value);
|
void updateConceptParamNoEscape(String id, String name, String value);
|
||||||
|
|
||||||
|
String getProfile(String profileId) throws ISLookUpException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,18 +79,21 @@ public class ISClientImpl implements ISClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Cacheable("context-cache-funder")
|
@Cacheable("context-cache-funder")
|
||||||
|
@Deprecated
|
||||||
public Map<String, Context> getFunderContextMap() throws IOException {
|
public Map<String, Context> getFunderContextMap() throws IOException {
|
||||||
return _processContext(_getQuery(config.getFindFunderContexts()));
|
return _processContext(_getQuery(config.getFindFunderContexts()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Cacheable("context-cache-community")
|
@Cacheable("context-cache-community")
|
||||||
|
@Deprecated
|
||||||
public Map<String, Context> getCommunityContextMap() throws IOException {
|
public Map<String, Context> getCommunityContextMap() throws IOException {
|
||||||
return _processContext(_getQuery(config.getFindCommunityContexts()));
|
return _processContext(_getQuery(config.getFindCommunityContexts()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Cacheable("context-cache")
|
@Cacheable("context-cache")
|
||||||
|
@Deprecated
|
||||||
public Map<String, Context> getContextMap(final List<String> type) throws IOException {
|
public Map<String, Context> getContextMap(final List<String> type) throws IOException {
|
||||||
if (Objects.isNull(type) || type.isEmpty()) {
|
if (Objects.isNull(type) || type.isEmpty()) {
|
||||||
return _processContext(_getQuery(config.getFindContextProfiles()));
|
return _processContext(_getQuery(config.getFindContextProfiles()));
|
||||||
|
@ -98,16 +101,15 @@ public class ISClientImpl implements ISClient {
|
||||||
try {
|
try {
|
||||||
final String xqueryTemplate = _getQuery(config.getFindContextProfilesByType());
|
final String xqueryTemplate = _getQuery(config.getFindContextProfilesByType());
|
||||||
final String xquery = String.format(xqueryTemplate, type.stream()
|
final String xquery = String.format(xqueryTemplate, type.stream()
|
||||||
.map(t -> String.format("./RESOURCE_PROFILE/BODY/CONFIGURATION/context/@type = '%s'", t))
|
.map(t -> String.format("./RESOURCE_PROFILE/BODY/CONFIGURATION/context/@type = '%s'", t))
|
||||||
.collect(Collectors.joining(" or ")));
|
.collect(Collectors.joining(" or ")));
|
||||||
|
|
||||||
return _processContext(xquery);
|
return _processContext(xquery);
|
||||||
}catch(Exception e){
|
} catch (final Exception e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +117,7 @@ public class ISClientImpl implements ISClient {
|
||||||
@CacheEvict(value = {
|
@CacheEvict(value = {
|
||||||
"context-cache", "context-cache-funder"
|
"context-cache", "context-cache-funder"
|
||||||
}, allEntries = true)
|
}, allEntries = true)
|
||||||
|
@Deprecated
|
||||||
public void updateContextParam(final String id, final String name, final String value, final boolean toEscape) {
|
public void updateContextParam(final String id, final String name, final String value, final boolean toEscape) {
|
||||||
if (getSize(id, name) > 0) {
|
if (getSize(id, name) > 0) {
|
||||||
try {
|
try {
|
||||||
|
@ -148,6 +151,7 @@ public class ISClientImpl implements ISClient {
|
||||||
@CacheEvict(value = {
|
@CacheEvict(value = {
|
||||||
"context-cache", "context-cache-funder"
|
"context-cache", "context-cache-funder"
|
||||||
}, allEntries = true)
|
}, allEntries = true)
|
||||||
|
@Deprecated
|
||||||
public void updateContextAttribute(final String id, final String name, final String value) {
|
public void updateContextAttribute(final String id, final String name, final String value) {
|
||||||
final Escaper esc = XmlEscapers.xmlAttributeEscaper();
|
final Escaper esc = XmlEscapers.xmlAttributeEscaper();
|
||||||
try {
|
try {
|
||||||
|
@ -162,6 +166,7 @@ public class ISClientImpl implements ISClient {
|
||||||
@CacheEvict(value = {
|
@CacheEvict(value = {
|
||||||
"context-cache", "context-cache-funder"
|
"context-cache", "context-cache-funder"
|
||||||
}, allEntries = true)
|
}, allEntries = true)
|
||||||
|
@Deprecated
|
||||||
public void addConcept(final String id, final String categoryId, final String data) {
|
public void addConcept(final String id, final String categoryId, final String data) {
|
||||||
try {
|
try {
|
||||||
_quickSeachProfile(String.format("update insert %s into collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" +
|
_quickSeachProfile(String.format("update insert %s into collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" +
|
||||||
|
@ -175,6 +180,7 @@ public class ISClientImpl implements ISClient {
|
||||||
@CacheEvict(value = {
|
@CacheEvict(value = {
|
||||||
"context-cache", "context-cache-funder"
|
"context-cache", "context-cache-funder"
|
||||||
}, allEntries = true)
|
}, allEntries = true)
|
||||||
|
@Deprecated
|
||||||
public void removeConcept(final String id, final String categoryId, final String conceptId) {
|
public void removeConcept(final String id, final String categoryId, final String conceptId) {
|
||||||
try {
|
try {
|
||||||
_quickSeachProfile(String.format("for $concept in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" +
|
_quickSeachProfile(String.format("for $concept in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType')" +
|
||||||
|
@ -190,6 +196,7 @@ public class ISClientImpl implements ISClient {
|
||||||
@CacheEvict(value = {
|
@CacheEvict(value = {
|
||||||
"context-cache", "context-cache-community", "context-cache-funder"
|
"context-cache", "context-cache-community", "context-cache-funder"
|
||||||
}, allEntries = true)
|
}, allEntries = true)
|
||||||
|
@Deprecated
|
||||||
public void updateConceptAttribute(final String id, final String name, final String value) {
|
public void updateConceptAttribute(final String id, final String name, final String value) {
|
||||||
final Escaper esc = XmlEscapers.xmlAttributeEscaper();
|
final Escaper esc = XmlEscapers.xmlAttributeEscaper();
|
||||||
try {
|
try {
|
||||||
|
@ -205,6 +212,7 @@ public class ISClientImpl implements ISClient {
|
||||||
@CacheEvict(value = {
|
@CacheEvict(value = {
|
||||||
"context-cache", "context-cache-funder"
|
"context-cache", "context-cache-funder"
|
||||||
}, allEntries = true)
|
}, allEntries = true)
|
||||||
|
@Deprecated
|
||||||
public void updateConceptParam(final String id, final String name, final String value) {
|
public void updateConceptParam(final String id, final String name, final String value) {
|
||||||
try {
|
try {
|
||||||
_quickSeachProfile(getConceptXQuery(id, name, value));
|
_quickSeachProfile(getConceptXQuery(id, name, value));
|
||||||
|
@ -217,6 +225,7 @@ public class ISClientImpl implements ISClient {
|
||||||
@CacheEvict(value = {
|
@CacheEvict(value = {
|
||||||
"context-cache", "context-cache-funder"
|
"context-cache", "context-cache-funder"
|
||||||
}, allEntries = true)
|
}, allEntries = true)
|
||||||
|
@Deprecated
|
||||||
public void updateConceptParamNoEscape(final String id, final String name, final String value) {
|
public void updateConceptParamNoEscape(final String id, final String name, final String value) {
|
||||||
try {
|
try {
|
||||||
_quickSeachProfile(getConceptXQueryNoEscape(id, name, value));
|
_quickSeachProfile(getConceptXQueryNoEscape(id, name, value));
|
||||||
|
@ -227,6 +236,7 @@ public class ISClientImpl implements ISClient {
|
||||||
|
|
||||||
/// HELPERS
|
/// HELPERS
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
private String getInsertXQuery(final String id, final String paramName, final String paramValue, final boolean toEscape) {
|
private String getInsertXQuery(final String id, final String paramName, final String paramValue, final boolean toEscape) {
|
||||||
String value;
|
String value;
|
||||||
if (toEscape) {
|
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) {
|
private String getXQuery(final String id, final String name, final String paramValue, final boolean toEscape) {
|
||||||
String value = paramValue;
|
String value = paramValue;
|
||||||
if (toEscape) {
|
if (toEscape) {
|
||||||
|
@ -269,6 +280,7 @@ public class ISClientImpl implements ISClient {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
private String getConceptXQuery(final String id, final String name, final String value) {
|
private String getConceptXQuery(final String id, final String name, final String value) {
|
||||||
final Escaper esc = XmlEscapers.xmlContentEscaper();
|
final Escaper esc = XmlEscapers.xmlContentEscaper();
|
||||||
if (StringUtils.isNotBlank(value)) {
|
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) {
|
private String getConceptXQueryNoEscape(final String id, final String name, final String value) {
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(value)) {
|
if (StringUtils.isNotBlank(value)) {
|
||||||
|
@ -291,10 +304,12 @@ public class ISClientImpl implements ISClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
private Map<String, Context> _processContext(final String xquery) throws IOException {
|
private Map<String, Context> _processContext(final String xquery) throws IOException {
|
||||||
return _processContext(new LinkedBlockingQueue<>(), xquery);
|
return _processContext(new LinkedBlockingQueue<>(), xquery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
private Map<String, Context> _processContext(final Queue<Throwable> errors, final String xquery) throws IOException {
|
private Map<String, Context> _processContext(final Queue<Throwable> errors, final String xquery) throws IOException {
|
||||||
try {
|
try {
|
||||||
return getContextProfiles(errors, xquery).stream()
|
return getContextProfiles(errors, xquery).stream()
|
||||||
|
@ -312,6 +327,7 @@ public class ISClientImpl implements ISClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
private List<String> getContextProfiles(final Queue<Throwable> errors, final String xquery) throws IOException {
|
private List<String> getContextProfiles(final Queue<Throwable> errors, final String xquery) throws IOException {
|
||||||
log.warn("getContextProfiles(): not using cache");
|
log.warn("getContextProfiles(): not using cache");
|
||||||
try {
|
try {
|
||||||
|
@ -335,13 +351,13 @@ public class ISClientImpl implements ISClient {
|
||||||
final List<String> res = Lists.newArrayList();
|
final List<String> res = Lists.newArrayList();
|
||||||
|
|
||||||
log.debug(String.format("running xquery:\n%s", xquery));
|
log.debug(String.format("running xquery:\n%s", xquery));
|
||||||
try{
|
try {
|
||||||
final List<String> list = isLookUpService.quickSearchProfile(xquery);
|
final List<String> list = isLookUpService.quickSearchProfile(xquery);
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
res.addAll(list);
|
res.addAll(list);
|
||||||
}
|
}
|
||||||
log.debug(String.format("query result size: %s", res.size()));
|
log.debug(String.format("query result size: %s", res.size()));
|
||||||
}catch(Exception ex){
|
} catch (final Exception ex) {
|
||||||
log.error(ex.getMessage());
|
log.error(ex.getMessage());
|
||||||
throw new ISLookUpException("");
|
throw new ISLookUpException("");
|
||||||
}
|
}
|
||||||
|
@ -358,4 +374,9 @@ public class ISClientImpl implements ISClient {
|
||||||
log.debug("dropped dsManager IS cache");
|
log.debug("dropped dsManager IS cache");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getProfile(final String profileId) throws ISLookUpException {
|
||||||
|
return isLookUpService.getResourceProfile(profileId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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<CommunitySummary> 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, "<![CDATA[" + new Gson().toJson(details.getAdvancedConstraints()) + "]]>", false);
|
|
||||||
|
|
||||||
}
|
|
||||||
if (details.getMainZenodoCommunity() != null) {
|
|
||||||
isClient.updateContextParam(id, CSUMMARY_ZENODOC, details.getMainZenodoCommunity(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
cc.updateCommunity(id, details);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CommunityProject> 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<Integer, CommunityProject> 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<CommunityProject> addCommunityProjectList(final String id, final List<CommunityProject> projectList) throws CommunityException, ResourceNotFoundException {
|
|
||||||
if(projectList == null || projectList.size() == 0){
|
|
||||||
throw new CommunityException("parameter 'projectList' must be present and should contain at least one project");
|
|
||||||
}
|
|
||||||
if (!StringUtils.equalsIgnoreCase(id, projectList.get(0).getCommunityId())) {
|
|
||||||
throw new CommunityException("parameters 'id' and project.communityId must be coherent");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<CommunityProject> projects = new ArrayList();
|
|
||||||
|
|
||||||
for(CommunityProject project : projectList){
|
|
||||||
projects.add(updateProject(id, project));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return projects;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String nextId(final Integer id) {
|
|
||||||
return String.valueOf(id + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeCommunityProject(final String id, final Integer projectId) throws CommunityException, ResourceNotFoundException {
|
|
||||||
final Map<Integer, CommunityProject> projects = getCommunityProjectMap(id);
|
|
||||||
if (!projects.containsKey(projectId)) {
|
|
||||||
throw new ResourceNotFoundException(String.format("project '%s' doesn't exist within context '%s'", projectId, id));
|
|
||||||
}
|
|
||||||
isClient.removeConcept(id, id + PROJECTS_ID_SUFFIX, id + PROJECTS_ID_SUFFIX + ID_SEPARATOR + projectId);
|
|
||||||
cc.removeFromCategory(id, PROJECTS_ID_SUFFIX, String.valueOf(projectId));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeCommunityProjectList(final String id, final List<Integer> projectIdList) throws CommunityException, ResourceNotFoundException {
|
|
||||||
for(Integer projectId: projectIdList){
|
|
||||||
removeCommunityProject(id, projectId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CommunityContentprovider> getCommunityContentproviders(final String id) throws CommunityException, ResourceNotFoundException {
|
|
||||||
cc.getCommunity(id); // ensure the community exists.
|
|
||||||
return cc.getCommunityInfo(id, CONTENTPROVIDERS_ID_SUFFIX, c -> CommunityMappingUtils.asCommunityDataprovider(id, c));
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommunityContentprovider addCommunityContentprovider(final String id, final CommunityContentprovider cp)
|
|
||||||
throws CommunityException, ResourceNotFoundException {
|
|
||||||
log.info("content provider to add " + cp.toString());
|
|
||||||
if (!StringUtils.equalsIgnoreCase(id, cp.getCommunityId())) { throw new CommunityException("parameters 'id' and cp.communityId must be coherent"); }
|
|
||||||
|
|
||||||
return updateContentprovider(id, cp);
|
|
||||||
}
|
|
||||||
|
|
||||||
private CommunityContentprovider updateContentprovider(String id, CommunityContentprovider cp) throws CommunityException, ResourceNotFoundException {
|
|
||||||
final TreeMap<Integer, CommunityContentprovider> cps = getCommunityContentproviderMap(id);
|
|
||||||
final String concept_id = cp.getId();
|
|
||||||
if (concept_id != null && cps.keySet().contains(Integer.valueOf(concept_id))) {
|
|
||||||
if (cp.getName() != null) {
|
|
||||||
isClient.updateConceptParam(id + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + concept_id, CCONTENTPROVIDER_NAME, cp.getName());
|
|
||||||
}
|
|
||||||
if (cp.getOfficialname() != null) {
|
|
||||||
isClient.updateConceptParam(id + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + concept_id, CCONTENTPROVIDER_OFFICIALNAME, cp.getOfficialname());
|
|
||||||
}
|
|
||||||
if (cp.getOpenaireId() != null) {
|
|
||||||
isClient.updateConceptParam(id + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + concept_id, OPENAIRE_ID, cp.getOpenaireId());
|
|
||||||
}
|
|
||||||
if (cp.getSelectioncriteria() != null) {
|
|
||||||
isClient.updateConceptParamNoEscape(id + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + concept_id, CCONTENTPROVIDER_SELCRITERIA, cp.toXML());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.info("adding new concept for community " + id);
|
|
||||||
cp.setId(nextId(!cps.isEmpty() ? cps.lastKey() : 0));
|
|
||||||
|
|
||||||
isClient.addConcept(id, id + CONTENTPROVIDERS_ID_SUFFIX, CommunityMappingUtils.asContentProviderXML(id, cp));
|
|
||||||
}
|
|
||||||
|
|
||||||
cc.updateDatasource(id, cp);
|
|
||||||
return cp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeCommunityContentProvider(final String id, final Integer contentproviderId) throws CommunityException, ResourceNotFoundException {
|
|
||||||
final Map<Integer, CommunityContentprovider> providers = getCommunityContentproviderMap(id);
|
|
||||||
if (!providers.containsKey(contentproviderId)) {
|
|
||||||
throw new ResourceNotFoundException(String.format("content provider '%s' doesn't exist within context '%s'", contentproviderId, id));
|
|
||||||
}
|
|
||||||
isClient.removeConcept(id, id + CONTENTPROVIDERS_ID_SUFFIX, id + CONTENTPROVIDERS_ID_SUFFIX + ID_SEPARATOR + contentproviderId);
|
|
||||||
cc.removeFromCategory(id, CONTENTPROVIDERS_ID_SUFFIX, String.valueOf(contentproviderId));
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CommunityContentprovider> addCommunityContentProvidersList(String id, List<CommunityContentprovider> contentprovidersList) throws CommunityException, ResourceNotFoundException {
|
|
||||||
if(contentprovidersList == null || contentprovidersList.size() == 0){
|
|
||||||
throw new CommunityException("parameter 'contentprovidersList' must be present and should contain at least one content provider");
|
|
||||||
}
|
|
||||||
if (!StringUtils.equalsIgnoreCase(id, contentprovidersList.get(0).getCommunityId())) {
|
|
||||||
throw new CommunityException("parameters 'id' and contentprovider.communityId must be coherent");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<CommunityContentprovider> contentproviders = new ArrayList();
|
|
||||||
|
|
||||||
for(CommunityContentprovider contentProvider : contentprovidersList){
|
|
||||||
contentproviders.add(updateContentprovider(id, contentProvider));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return contentproviders;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeCommunityContentProviderList(final String id, final List<Integer> contentProviderIdList) throws CommunityException, ResourceNotFoundException {
|
|
||||||
for(Integer contentProviderId: contentProviderIdList){
|
|
||||||
removeCommunityContentProvider(id, contentProviderId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeCommunityOrganization(final String id, final Integer organizationId) throws CommunityException, ResourceNotFoundException {
|
|
||||||
final Map<Integer, CommunityOrganization> organizations = getCommunityOrganizationMap(id);
|
|
||||||
if (!organizations.containsKey(organizationId)) {
|
|
||||||
throw new ResourceNotFoundException(String.format("organization '%s' doesn't exist within context '%s'", organizationId, id));
|
|
||||||
}
|
|
||||||
isClient.removeConcept(id, id + ORGANIZATION_ID_SUFFIX, id + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organizationId);
|
|
||||||
cc.removeFromCategory(id, ORGANIZATION_ID_SUFFIX, String.valueOf(organizationId));
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(final String id) throws CommunityException, ResourceNotFoundException {
|
|
||||||
|
|
||||||
return cc.getCommunityZenodoCommunities(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CommunityOrganization> 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<String> subjects) throws CommunityException, ResourceNotFoundException {
|
|
||||||
|
|
||||||
final CommunityDetails cd = new CommunityDetails();
|
|
||||||
|
|
||||||
final Set<String> 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<String> subjects) throws CommunityException, ResourceNotFoundException {
|
|
||||||
|
|
||||||
final CommunityDetails cd = new CommunityDetails();
|
|
||||||
|
|
||||||
final Set<String> 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<String> foss) throws CommunityException, ResourceNotFoundException {
|
|
||||||
|
|
||||||
final CommunityDetails cd = new CommunityDetails();
|
|
||||||
|
|
||||||
final Set<String> current = Sets.newHashSet();
|
|
||||||
if(Optional.ofNullable(cc.getCommunity(id).getFos()).isPresent()){
|
|
||||||
current.addAll(cc.getCommunity(id).getFos());
|
|
||||||
}
|
|
||||||
|
|
||||||
current.addAll(foss);
|
|
||||||
|
|
||||||
cd.setFos(Lists.newArrayList(current));
|
|
||||||
|
|
||||||
setCommunity(id, CommunityWritableProperties.fromDetails(cd));
|
|
||||||
|
|
||||||
return cd;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommunityDetails removeCommunityFOS(final String id, final List<String> foss) throws CommunityException, ResourceNotFoundException {
|
|
||||||
|
|
||||||
final CommunityDetails cd = new CommunityDetails();
|
|
||||||
|
|
||||||
final Set<String> current = Sets.newHashSet(cc.getCommunity(id).getFos());
|
|
||||||
|
|
||||||
current.removeAll(foss);
|
|
||||||
|
|
||||||
cd.setFos(Lists.newArrayList(current));
|
|
||||||
|
|
||||||
setCommunity(id, CommunityWritableProperties.fromDetails(cd));
|
|
||||||
|
|
||||||
return cd;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommunityDetails addCommunitySDG(final String id, final List<String> sdgs) throws CommunityException, ResourceNotFoundException {
|
|
||||||
|
|
||||||
final CommunityDetails cd = new CommunityDetails();
|
|
||||||
final Set<String> current = Sets.newHashSet();
|
|
||||||
if(Optional.ofNullable(cc.getCommunity(id).getSdg()).isPresent()){
|
|
||||||
current.addAll(cc.getCommunity(id).getSdg());
|
|
||||||
}
|
|
||||||
|
|
||||||
current.addAll(sdgs);
|
|
||||||
|
|
||||||
cd.setSdg(Lists.newArrayList(current));
|
|
||||||
|
|
||||||
setCommunity(id, CommunityWritableProperties.fromDetails(cd));
|
|
||||||
|
|
||||||
return cd;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommunityDetails removeCommunitySDG(final String id, final List<String> sdgs) throws CommunityException, ResourceNotFoundException {
|
|
||||||
|
|
||||||
final CommunityDetails cd = new CommunityDetails();
|
|
||||||
|
|
||||||
final Set<String> current = Sets.newHashSet(cc.getCommunity(id).getSdg());
|
|
||||||
|
|
||||||
current.removeAll(sdgs);
|
|
||||||
|
|
||||||
cd.setSdg(Lists.newArrayList(current));
|
|
||||||
|
|
||||||
setCommunity(id, CommunityWritableProperties.fromDetails(cd));
|
|
||||||
|
|
||||||
return cd;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommunityDetails addCommunityAdvancedConstraint(final String id, final SelectionCriteria advancedCosntraint) throws CommunityException, 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<Integer, CommunityZenodoCommunity> 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<Integer, CommunityZenodoCommunity> 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<Integer, CommunityProject> getCommunityProjectMap(final String id) throws CommunityException, ResourceNotFoundException {
|
|
||||||
return getCommunityProjects(id).stream()
|
|
||||||
.collect(Collectors.toMap(p -> Integer.valueOf(p.getId()), Functions.identity(), (p1, p2) -> {
|
|
||||||
log.warn(String.format("duplicate project found: '%s'", p1.getId()));
|
|
||||||
return p2;
|
|
||||||
}, TreeMap::new));
|
|
||||||
}
|
|
||||||
|
|
||||||
private TreeMap<Integer, CommunityContentprovider> getCommunityContentproviderMap(final String id) throws CommunityException, ResourceNotFoundException {
|
|
||||||
log.info("getting community content provider map");
|
|
||||||
return getCommunityContentproviders(id).stream()
|
|
||||||
.collect(Collectors.toMap(cp -> Integer.valueOf(cp.getId()), Functions.identity(), (cp1, cp2) -> {
|
|
||||||
log.warn(String.format("duplicate content provider found: '%s'", cp1.getId()));
|
|
||||||
return cp2;
|
|
||||||
}, TreeMap::new));
|
|
||||||
}
|
|
||||||
|
|
||||||
private TreeMap<Integer, CommunityZenodoCommunity> getZenodoCommunityMap(final String id) throws CommunityException, ResourceNotFoundException {
|
|
||||||
return getCommunityZenodoCommunities(id).stream()
|
|
||||||
.collect(Collectors.toMap(cp -> Integer.valueOf(cp.getId()), Functions.identity(), (cp1, cp2) -> {
|
|
||||||
log.warn(String.format("duplicate Zenodo community found: '%s'", cp1.getId()));
|
|
||||||
return cp2;
|
|
||||||
}, TreeMap::new));
|
|
||||||
}
|
|
||||||
|
|
||||||
private TreeMap<Integer, CommunityOrganization> getCommunityOrganizationMap(final String id) throws CommunityException, ResourceNotFoundException {
|
|
||||||
return getCommunityOrganizations(id).stream()
|
|
||||||
.collect(Collectors.toMap(o -> Integer.valueOf(o.getId()), Functions.identity(), (o1, o2) -> {
|
|
||||||
log.warn(String.format("duplicate content provider found: '%s'", o1.getId()));
|
|
||||||
return o2;
|
|
||||||
}, TreeMap::new));
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommunityOrganization addCommunityOrganization(final String id, final CommunityOrganization organization)
|
|
||||||
throws CommunityException, ResourceNotFoundException {
|
|
||||||
if (!StringUtils.equalsIgnoreCase(id, organization.getCommunityId())) {
|
|
||||||
throw new CommunityException("parameters 'id' and organization.communityId must be coherent");
|
|
||||||
}
|
|
||||||
|
|
||||||
final TreeMap<Integer, CommunityOrganization> cps = getCommunityOrganizationMap(id);
|
|
||||||
|
|
||||||
final String organization_id = organization.getId();
|
|
||||||
if (organization_id != null && cps.keySet().contains(Integer.valueOf(organization_id))) {
|
|
||||||
if (organization.getName() != null) {
|
|
||||||
isClient.updateConceptParam(id + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organization_id, CORGANIZATION_NAME, organization.getName());
|
|
||||||
}
|
|
||||||
if (organization.getLogo_url() != null) {
|
|
||||||
isClient.updateConceptParam(id + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organization_id, CORGANIZATION_LOGOURL, Base64.getEncoder()
|
|
||||||
.encodeToString(organization.getLogo_url().getBytes()));
|
|
||||||
}
|
|
||||||
if (organization.getWebsite_url() != null) {
|
|
||||||
isClient.updateConceptParam(id + ORGANIZATION_ID_SUFFIX + ID_SEPARATOR + organization_id, CORGANIZATION_WEBSITEURL, Base64.getEncoder()
|
|
||||||
.encodeToString(organization.getWebsite_url().getBytes()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
organization.setId(nextId(!cps.isEmpty() ? cps.lastKey() : 0));
|
|
||||||
isClient.addConcept(id, id + ORGANIZATION_ID_SUFFIX, CommunityMappingUtils.asOrganizationXML(id, organization));
|
|
||||||
}
|
|
||||||
|
|
||||||
cc.updateOrganization(id, organization);
|
|
||||||
return organization;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -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<String, Set<String>> getInverseZenodoCommunityMap() throws CommunityException, ResourceNotFoundException;
|
|
||||||
|
|
||||||
void dropCache();
|
|
||||||
|
|
||||||
}
|
|
|
@ -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<String, Set<String>> getInverseZenodoCommunityMap () throws CommunityException, ResourceNotFoundException {
|
|
||||||
log.info("Creating the data structure. Not using cache");
|
|
||||||
final Map<String, Set<String>> inverseListMap = new HashMap<>();
|
|
||||||
|
|
||||||
final List<CommunitySummary> communityList = communityCommon.listCommunities();
|
|
||||||
|
|
||||||
for(CommunitySummary cs :communityList){
|
|
||||||
final String communityId = cs.getId();
|
|
||||||
List<CommunityZenodoCommunity> czc = communityCommon.getCommunityZenodoCommunities(communityId);
|
|
||||||
for(CommunityZenodoCommunity zc:czc){
|
|
||||||
final String zenodoId = zc.getZenodoid();
|
|
||||||
if(!inverseListMap.containsKey(zenodoId)) {
|
|
||||||
inverseListMap.put(zc.getZenodoid(),new HashSet<>());
|
|
||||||
}
|
|
||||||
inverseListMap.get(zc.getZenodoid()).add(communityId);
|
|
||||||
}
|
|
||||||
final String zenodoMainCommunity = communityCommon.getCommunity(communityId).getZenodoCommunity();
|
|
||||||
if(!inverseListMap.containsKey(zenodoMainCommunity)) {
|
|
||||||
inverseListMap.put(zenodoMainCommunity,new HashSet<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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<String, Context> getContextMap() throws CommunityException {
|
|
||||||
try {
|
|
||||||
return isClient.getCommunityContextMap();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new CommunityException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CommunitySummary> listCommunities() throws CommunityException {
|
|
||||||
return getContextMap().values().stream()
|
|
||||||
.filter(context -> !communityBlackList.contains(context.getId()))
|
|
||||||
.map(CommunityMappingUtils::asCommunitySummary)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public <R> List<R> getCommunityInfo(final String id, final String idSuffix, final Function<Concept, R> mapping) throws CommunityException {
|
|
||||||
final Map<String, Context> contextMap = getContextMap();
|
|
||||||
final Context context = contextMap.get(id);
|
|
||||||
if (context != null) {
|
|
||||||
final Map<String, Category> categories = context.getCategories();
|
|
||||||
final Category category = categories.get(id + idSuffix);
|
|
||||||
if (category != null) {
|
|
||||||
return category.getConcepts().stream()
|
|
||||||
.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<CommunityZenodoCommunity> 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<String, List<Param>> params = new TreeMap<>();
|
|
||||||
|
|
||||||
if(project.getAcronym() != null){
|
|
||||||
params.put(CPROJECT_ACRONYM, Arrays.asList(new Param().setName(CPROJECT_ACRONYM)
|
|
||||||
.setValue(project.getAcronym())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (project.getName() != null){
|
|
||||||
params.put(CPROJECT_FULLNAME, Arrays.asList(new Param()
|
|
||||||
.setName(CPROJECT_FULLNAME)
|
|
||||||
.setValue(project.getName())
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (project.getOpenaireId() != null){
|
|
||||||
params.put(OPENAIRE_ID, Arrays.asList(new Param()
|
|
||||||
.setName(OPENAIRE_ID)
|
|
||||||
.setValue(project.getOpenaireId())
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(project.getFunder() != null){
|
|
||||||
params.put(CPROJECT_FUNDER, Arrays.asList(new Param()
|
|
||||||
.setName(CPROJECT_FUNDER)
|
|
||||||
.setValue(project.getFunder())
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (project.getGrantId()!=null){
|
|
||||||
params.put(CPROJECT_NUMBER, Arrays.asList(new Param()
|
|
||||||
.setName(CPROJECT_NUMBER)
|
|
||||||
.setValue(project.getGrantId())
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
concept.setParams(params);
|
|
||||||
prj.getConcepts().add(concept);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeAdvancedConstraint(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<String, Context> cmap = getContextMap();
|
|
||||||
Context context = cmap.get(communityId);
|
|
||||||
Map<String, Category> cat = context.getCategories();
|
|
||||||
|
|
||||||
List<Concept> concepts = cat.get(communityId + category).getConcepts()
|
|
||||||
.stream().filter(c -> !c.getId().equals(communityId + category + ID_SEPARATOR + conceptId)).collect(Collectors.toList());
|
|
||||||
|
|
||||||
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<String, List<Param>> params = new TreeMap<>();
|
|
||||||
|
|
||||||
if (cp.getName() != null) {
|
|
||||||
params.put( CCONTENTPROVIDER_NAME, Arrays.asList(new Param().setValue(cp.getName()).setName(CCONTENTPROVIDER_NAME)));
|
|
||||||
}
|
|
||||||
if(cp.getOfficialname()!= null){
|
|
||||||
params.put( CCONTENTPROVIDER_OFFICIALNAME, Arrays.asList(new Param().setValue(cp.getOfficialname()).setName(CCONTENTPROVIDER_OFFICIALNAME)));
|
|
||||||
}
|
|
||||||
if (cp.getOpenaireId() != null){
|
|
||||||
params.put( OPENAIRE_ID, Arrays.asList(new Param().setValue(cp.getOpenaireId()).setName(OPENAIRE_ID)));
|
|
||||||
}
|
|
||||||
if(cp.getSelectioncriteria() != null){
|
|
||||||
params.put( CCONTENTPROVIDER_SELCRITERIA, Arrays.asList(new Param().setValue(cp.toJson()).setName(CCONTENTPROVIDER_SELCRITERIA)));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
concept.setParams(params);
|
|
||||||
dts.getConcepts().add(concept);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateOrganization(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<String, List<Param>> params = new TreeMap<>();
|
|
||||||
|
|
||||||
if (organization.getName() != null) {
|
|
||||||
params.put( CORGANIZATION_NAME, Arrays.asList(new Param().setValue(organization.getName()).setName(CORGANIZATION_NAME)));
|
|
||||||
}
|
|
||||||
if(organization.getLogo_url()!= null){
|
|
||||||
|
|
||||||
params.put( CORGANIZATION_LOGOURL, Arrays.asList(new Param().setValue(Base64.getEncoder().encodeToString(organization.getLogo_url().getBytes())).setName(CORGANIZATION_LOGOURL)));
|
|
||||||
}
|
|
||||||
if (organization.getWebsite_url() != null){
|
|
||||||
params.put( CORGANIZATION_WEBSITEURL, Arrays.asList(new Param().setValue(Base64.getEncoder().encodeToString(organization.getWebsite_url().getBytes())).setName(CORGANIZATION_WEBSITEURL)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
concept.setParams(params);
|
|
||||||
orgs.getConcepts().add(concept);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateZenodoCommunity(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<String, List<Param>> 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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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<String> 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";
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -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<String, List<Param>> 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<String, List<Param>> 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<String, List<Param>> 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<String, List<Param>> 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<String, List<Param>> p = c.getParams();
|
|
||||||
z.setCommunityId(communityId);
|
|
||||||
z.setId(StringUtils.substringAfterLast(c.getId(), ID_SEPARATOR));
|
|
||||||
z.setZenodoid(firstValue(p,CZENODOCOMMUNITY_ID));
|
|
||||||
//z.setName(c.getLabel());
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static CommunityOrganization asCommunityOrganization(String id, Concept c) {
|
|
||||||
final Map<String, List<Param>> p = c.getParams();
|
|
||||||
final CommunityOrganization o = new CommunityOrganization();
|
|
||||||
o.setCommunityId(id);
|
|
||||||
o.setId(StringUtils.substringAfterLast(c.getId(), ID_SEPARATOR));
|
|
||||||
o.setName(firstValue(p,CORGANIZATION_NAME));
|
|
||||||
o.setLogo_url(getDecodedUrl(firstValue(p,CORGANIZATION_LOGOURL)));
|
|
||||||
o.setWebsite_url(getDecodedUrl(firstValue(p,CORGANIZATION_WEBSITEURL)));
|
|
||||||
|
|
||||||
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<String> splitValues(final Stream<String> stream, final String separator) {
|
|
||||||
return stream.map(s -> s.split(separator))
|
|
||||||
.map(Arrays::asList)
|
|
||||||
.flatMap(List::stream)
|
|
||||||
.filter(StringUtils::isNotBlank)
|
|
||||||
.map(StringUtils::trim)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String firstValue(final Map<String, List<Param>> p, final String paramName) {
|
|
||||||
return asValues(p.get(paramName)).findFirst().orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String asCsv(final List<Param> params) {
|
|
||||||
return asValues(params)
|
|
||||||
.collect(Collectors.joining(CSV_DELIMITER));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Stream<String> asValues(final List<Param> 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(
|
|
||||||
"<concept claim='false' id='%s%s%s%s' label='%s'>\n",
|
|
||||||
escape(esc, contextId), PROJECTS_ID_SUFFIX, ID_SEPARATOR, escape(esc, String.valueOf(project.getId())), escape(esc, project.getAcronym())));
|
|
||||||
sb.append(paramXML(CPROJECT_FULLNAME, project.getName()));
|
|
||||||
sb.append(paramXML(CPROJECT_ACRONYM, project.getAcronym()));
|
|
||||||
sb.append(paramXML(CPROJECT_NUMBER, project.getGrantId()));
|
|
||||||
sb.append(paramXML(CPROJECT_FUNDER, project.getFunder()));
|
|
||||||
sb.append(paramXML(OPENAIRE_ID, project.getOpenaireId()));
|
|
||||||
sb.append("</concept>\n");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String asContentProviderXML(final String contextId, final CommunityContentprovider ccp) {
|
|
||||||
log.info("creating the XML for the content provider");
|
|
||||||
final Escaper esc = XmlEscapers.xmlAttributeEscaper();
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append(
|
|
||||||
String.format(
|
|
||||||
"<concept claim='false' id='%s%s%s%s' label='%s'>\n",
|
|
||||||
escape(esc, contextId), CONTENTPROVIDERS_ID_SUFFIX, ID_SEPARATOR, escape(esc, String.valueOf(ccp.getId())), escape(esc, ccp.getName())));
|
|
||||||
sb.append(paramXML(OPENAIRE_ID, ccp.getOpenaireId()));
|
|
||||||
sb.append(paramXML(CCONTENTPROVIDER_NAME, ccp.getName()));
|
|
||||||
sb.append(paramXML(CCONTENTPROVIDER_OFFICIALNAME, ccp.getOfficialname()));
|
|
||||||
sb.append(paramXML(CCONTENTPROVIDER_ENABLED,CCONTENTPROVIDERENABLED_DEFAULT));
|
|
||||||
sb.append(paramXMLNoEscape(CCONTENTPROVIDER_SELCRITERIA, ccp.toXML()));
|
|
||||||
sb.append("</concept>\n");
|
|
||||||
log.info(sb.toString());
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String asZenodoCommunityXML(final String contextId, final CommunityZenodoCommunity zc) {
|
|
||||||
final Escaper esc = XmlEscapers.xmlAttributeEscaper();
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append(
|
|
||||||
String.format(
|
|
||||||
"<concept claim='false' id='%s%s%s%s' label='%s'>\n",
|
|
||||||
escape(esc, contextId), ZENODOCOMMUNITY_ID_SUFFIX, ID_SEPARATOR, escape(esc, String.valueOf(zc.getId())), escape(esc, zc.getZenodoid())));
|
|
||||||
|
|
||||||
sb.append(paramXML(CZENODOCOMMUNITY_ID, zc.getZenodoid()));
|
|
||||||
sb.append("</concept>\n");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static String asOrganizationXML(final String contextId, CommunityOrganization organization) {
|
|
||||||
final Escaper esc = XmlEscapers.xmlAttributeEscaper();
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append(
|
|
||||||
String.format(
|
|
||||||
"<concept claim='false' id='%s%s%s%s' label='%s'>\n",
|
|
||||||
escape(esc, contextId), ORGANIZATION_ID_SUFFIX, ID_SEPARATOR, escape(esc, String.valueOf(organization.getId())), escape(esc, organization.getName())));
|
|
||||||
sb.append(paramXML(CORGANIZATION_NAME, organization.getName()));
|
|
||||||
sb.append(paramXML(CORGANIZATION_LOGOURL, Base64.getEncoder().encodeToString(organization.getLogo_url().getBytes())));
|
|
||||||
sb.append(paramXML(CORGANIZATION_WEBSITEURL,Base64.getEncoder().encodeToString(organization.getWebsite_url().getBytes())));
|
|
||||||
sb.append("</concept>\n");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static String paramXML(final String paramName, final String value) {
|
|
||||||
return String.format("<param name='%s'>%s</param>\n", paramName, escape(XmlEscapers.xmlContentEscaper(), value));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String paramXMLNoEscape(final String paramName, final String value) {
|
|
||||||
return String.format("<param name='%s'>%s</param>\n", paramName, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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<CommunitySummary> 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<CommunityProject> 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<DbProject> 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<DbProject> prepareProjectSpec(final String community, final String funder, final String other) {
|
||||||
|
return (project, query, cb) -> {
|
||||||
|
|
||||||
|
final List<Predicate> 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<Predicate> 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<DbProject> 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<DbProjectPK> list = Arrays.stream(ids)
|
||||||
|
.map(projectId -> new DbProjectPK(id, projectId))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
dbProjectRepository.deleteAllById(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CommunityContentprovider> 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<DbDatasource> 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<DbDatasourcePK> 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<DbSupportOrgPK> list = Arrays.stream(orgNames)
|
||||||
|
.map(name -> new DbSupportOrgPK(id, name))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
dbSupportOrgRepository.deleteAllById(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public List<CommunityOrganization> 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<DbSupportOrg> 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<SubCommunity> 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<DbSubCommunity> 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<DbCommunity, String> 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<DbCommunity, String[]> getter,
|
||||||
|
final BiConsumer<DbCommunity, String[]> setter,
|
||||||
|
final boolean remove,
|
||||||
|
final String... values) {
|
||||||
|
|
||||||
|
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
|
|
||||||
|
final Set<String> 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<String> getOpenAIRECommunitiesByZenodoId(final String zenodoId) {
|
||||||
|
return dbCommunityRepository.findByZenodoId(zenodoId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Map<String, Set<String>> getPropagationOrganizationCommunityMap() {
|
||||||
|
return dbOrganizationRepository.findAll()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.groupingBy(DbOrganization::getOrgId, Collectors.mapping(DbOrganization::getCommunity, Collectors.toSet())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Set<String> getPropagationOrganizationsForCommunity(final String communityId) {
|
||||||
|
return dbOrganizationRepository.findByCommunity(communityId)
|
||||||
|
.stream()
|
||||||
|
.map(DbOrganization::getOrgId)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Set<String> 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<String> 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<IISConfigurationEntry> getIISConfiguration(final String id) {
|
||||||
|
final List<IISConfigurationEntry> 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<String> getCommunityFunders(final String id) {
|
||||||
|
return dbProjectRepository.findFundersByCommunity(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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<String> communityBlackList = Sets.newHashSet("fet-fp7", "fet-h2020");
|
||||||
|
public final static Set<String> 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<String> importProfiles() throws CommunityException {
|
||||||
|
try {
|
||||||
|
final Map<String, Context> contextMap = getContextMap();
|
||||||
|
|
||||||
|
final List<String> 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<DbOrganization> 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<String, Context> getContextMap() throws CommunityException {
|
||||||
|
try {
|
||||||
|
return isClient.getCommunityContextMap();
|
||||||
|
} catch (final IOException e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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<DbOrganization> 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<DbOrganization> list = new ObjectMapper()
|
||||||
|
.readValue(json, new TypeReference<Map<String, List<String>>>() {})
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.flatMap(e -> e.getValue()
|
||||||
|
.stream()
|
||||||
|
.map(community -> {
|
||||||
|
if (e.getKey().contains("|")) {
|
||||||
|
return new DbOrganization(community, StringUtils.substringAfter(e.getKey(), "|"));
|
||||||
|
} else {
|
||||||
|
return new DbOrganization(community, e.getKey());
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (!simulation) {
|
||||||
|
list.forEach(o -> {
|
||||||
|
try {
|
||||||
|
dbOrganizationRepository.save(o);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error("ERROR saving org: " + o);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void importCommunity(final Context context) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
final CommunityDetails community = asCommunityDetails(context);
|
||||||
|
|
||||||
|
final List<CommunityContentprovider> datasources =
|
||||||
|
getCommunityInfo(context, CONTENTPROVIDERS_ID_SUFFIX, c -> asCommunityDataprovider(context.getId(), c))
|
||||||
|
.stream()
|
||||||
|
.map(o -> {
|
||||||
|
if (o.getOpenaireId() == null) {
|
||||||
|
log.warn("Openaire ID is missing, organization: " + o.getOfficialname());
|
||||||
|
} else if (o.getOpenaireId().contains("|")) {
|
||||||
|
o.setOpenaireId(StringUtils.substringAfter(o.getOpenaireId(), "|"));
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
})
|
||||||
|
.filter(o -> o.getOpenaireId() != null)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
final List<CommunityProject> projects =
|
||||||
|
getCommunityInfo(context, PROJECTS_ID_SUFFIX, c -> asCommunityProject(context.getId(), c))
|
||||||
|
.stream()
|
||||||
|
.map(p -> {
|
||||||
|
if (p.getOpenaireId() == null) {
|
||||||
|
if (p.getFunder().equalsIgnoreCase("EC")) {
|
||||||
|
final String ns = findNamespaceForECProject(p.getGrantId());
|
||||||
|
if (ns != null) {
|
||||||
|
p.setOpenaireId(ns + "::" + Hashing.md5(p.getGrantId()));
|
||||||
|
} else {
|
||||||
|
log.warn("EC project not in the db: " + p.getGrantId());
|
||||||
|
}
|
||||||
|
} else if (p.getFunder().equalsIgnoreCase("NSF")) {
|
||||||
|
p.setOpenaireId("nsf_________::" + Hashing.md5(p.getGrantId()));
|
||||||
|
} else if (p.getFunder().equalsIgnoreCase("NIH")) {
|
||||||
|
p.setOpenaireId("nih_________::" + Hashing.md5(p.getGrantId()));
|
||||||
|
} else {
|
||||||
|
log.warn("Openaire ID is missing, funder: " + p.getFunder());
|
||||||
|
}
|
||||||
|
} else if (p.getOpenaireId().contains("|")) {
|
||||||
|
p.setOpenaireId(StringUtils.substringAfter(p.getOpenaireId(), "|"));
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
})
|
||||||
|
.filter(p -> p.getOpenaireId() != null)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
final List<CommunityOrganization> orgs =
|
||||||
|
getCommunityInfo(context, ORGANIZATION_ID_SUFFIX, c -> asCommunityOrganization(context.getId(), c));
|
||||||
|
|
||||||
|
final List<String> otherZenodoCommunities =
|
||||||
|
getCommunityInfo(context, ZENODOCOMMUNITY_ID_SUFFIX, c -> asZenodoCommunity(c));
|
||||||
|
|
||||||
|
community.setOtherZenodoCommunities(otherZenodoCommunities);
|
||||||
|
|
||||||
|
final List<SubCommunity> subs = context.getCategories()
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.filter(e -> !e.getKey().equals(context.getId() + CONTENTPROVIDERS_ID_SUFFIX))
|
||||||
|
.filter(e -> !e.getKey().equals(context.getId() + PROJECTS_ID_SUFFIX))
|
||||||
|
.filter(e -> !e.getKey().equals(context.getId() + ORGANIZATION_ID_SUFFIX))
|
||||||
|
.filter(e -> !e.getKey().equals(context.getId() + ZENODOCOMMUNITY_ID_SUFFIX))
|
||||||
|
.map(e -> e.getValue())
|
||||||
|
.map(cat -> asSubCommunities(context.getId(), null, cat.getLabel(), cat.getConcepts()))
|
||||||
|
.flatMap(List::stream)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
service.saveCommunity(community);
|
||||||
|
service.addCommunityProjects(context.getId(), projects.toArray(new CommunityProject[projects.size()]));
|
||||||
|
service.addCommunityContentProviders(context.getId(), datasources.toArray(new CommunityContentprovider[datasources.size()]));
|
||||||
|
service.addCommunityOrganizations(context.getId(), orgs.toArray(new CommunityOrganization[orgs.size()]));
|
||||||
|
service.addSubCommunities(context.getId(), subs.toArray(new SubCommunity[subs.size()]));
|
||||||
|
} catch (
|
||||||
|
|
||||||
|
final Exception e) {
|
||||||
|
throw new RuntimeException("Error importing community: " + context.getId(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private <R> List<R> getCommunityInfo(final Context context, final String idSuffix, final Function<Concept, R> mapping)
|
||||||
|
throws CommunityException {
|
||||||
|
if (context != null) {
|
||||||
|
final Map<String, Category> categories = context.getCategories();
|
||||||
|
final Category category = categories.get(context.getId() + idSuffix);
|
||||||
|
if (category != null) { return category.getConcepts()
|
||||||
|
.stream()
|
||||||
|
.map(mapping)
|
||||||
|
.collect(Collectors.toList()); }
|
||||||
|
}
|
||||||
|
return Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CommunityDetails asCommunityDetails(final Context c) {
|
||||||
|
|
||||||
|
final CommunityDetails details = new CommunityDetails();
|
||||||
|
|
||||||
|
details.setId(c.getId());
|
||||||
|
details.setShortName(c.getLabel());
|
||||||
|
details.setLastUpdateDate(CommunityMappingUtils.asLocalDateTime(c.getLastUpdateDate()));
|
||||||
|
details.setCreationDate(CommunityMappingUtils.asLocalDateTime(c.getCreationDate()));
|
||||||
|
details.setQueryId(c.getId() + PIPE_SEPARATOR + c.getLabel());
|
||||||
|
details.setType(CommunityType.valueOf(c.getType()));
|
||||||
|
details.setMembership(CommunityMembershipType.open);
|
||||||
|
details.setClaim(CommunityClaimType.all);
|
||||||
|
details.setDescription(asCsv(CSUMMARY_DESCRIPTION, c.getParams()));
|
||||||
|
details.setLogoUrl(asCsv(CSUMMARY_LOGOURL, c.getParams()));
|
||||||
|
|
||||||
|
final String status = firstValue(CSUMMARY_STATUS, c.getParams());
|
||||||
|
if (StringUtils.isNotBlank(status)) {
|
||||||
|
details.setStatus(CommunityStatus.valueOf(status));
|
||||||
|
} else {
|
||||||
|
details.setStatus(CommunityStatus.hidden);
|
||||||
|
}
|
||||||
|
|
||||||
|
details.setName(StringUtils.firstNonBlank(asCsv(CSUMMARY_NAME, c.getParams()), c.getLabel()));
|
||||||
|
details.setZenodoCommunity(asCsv(CSUMMARY_ZENODOC, c.getParams()));
|
||||||
|
details.setSubjects(splitValues(asValues(CPROFILE_SUBJECT, c.getParams()), CSV_DELIMITER));
|
||||||
|
details.setFos(splitValues(asValues(CPROFILE_FOS, c.getParams()), CSV_DELIMITER));
|
||||||
|
details.setSdg(splitValues(asValues(CPROFILE_SDG, c.getParams()), CSV_DELIMITER));
|
||||||
|
// In the map the string is the serialization of the json representing the selection criteria so it is a valid json
|
||||||
|
details.setAdvancedConstraints(SelectionCriteria.fromJson(asCsv(CPROFILE_ADVANCED_CONSTRAINT, c.getParams())));
|
||||||
|
// In the map the string is the serialization of the json representing the selection criteria so it is a valid json
|
||||||
|
details.setRemoveConstraints(SelectionCriteria.fromJson(asCsv(CPROFILE_REMOVE_CONSTRAINT, c.getParams())));
|
||||||
|
details.setSuggestedAcknowledgements(splitValues(asValues(CPROFILE_SUGGESTED_ACKNOWLEDGEMENT, c.getParams()), CSV_DELIMITER));
|
||||||
|
details.setPlan(null);
|
||||||
|
try {
|
||||||
|
details.setCreationDate(CommunityMappingUtils.asLocalDateTime(asCsv(CPROFILE_CREATIONDATE, c.getParams())));
|
||||||
|
} catch (final Exception e) {
|
||||||
|
log.debug("Exception on date format: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return details;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CommunityProject asCommunityProject(final String communityId, final Concept c) {
|
||||||
|
final List<Param> p = c.getParams();
|
||||||
|
final CommunityProject project = new CommunityProject();
|
||||||
|
project.setCommunityId(communityId);
|
||||||
|
project.setOpenaireId(firstValue(OPENAIRE_ID, p));
|
||||||
|
project.setFunder(firstValue(CPROJECT_FUNDER, p));
|
||||||
|
project.setGrantId(firstValue(CPROJECT_NUMBER, p));
|
||||||
|
project.setName(firstValue(CPROJECT_FULLNAME, p));
|
||||||
|
project.setAcronym(firstValue(CPROJECT_ACRONYM, p));
|
||||||
|
project.setAvailableSince(LocalDate.of(2017, 2, 25)); // Birillo Birth Date
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CommunityContentprovider asCommunityDataprovider(final String communityId, final Concept c) {
|
||||||
|
final List<Param> p = c.getParams();
|
||||||
|
final CommunityContentprovider d = new CommunityContentprovider();
|
||||||
|
d.setCommunityId(communityId);
|
||||||
|
d.setOpenaireId(firstValue(OPENAIRE_ID, p));
|
||||||
|
d.setName(firstValue(CCONTENTPROVIDER_NAME, p));
|
||||||
|
d.setOfficialname(firstValue(CCONTENTPROVIDER_OFFICIALNAME, p));
|
||||||
|
d.setEnabled(BooleanUtils.toBoolean(firstValue(CCONTENTPROVIDER_ENABLED, p)));
|
||||||
|
d.setSelectioncriteria(SelectionCriteria.fromJson(firstValue(CCONTENTPROVIDER_SELCRITERIA, p)));
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CommunityOrganization asCommunityOrganization(final String id, final Concept c) {
|
||||||
|
final List<Param> p = c.getParams();
|
||||||
|
final CommunityOrganization o = new CommunityOrganization();
|
||||||
|
o.setCommunityId(id);
|
||||||
|
o.setName(firstValue(CORGANIZATION_NAME, p));
|
||||||
|
o.setLogo_url(getDecodedUrl(firstValue(CORGANIZATION_LOGOURL, p)));
|
||||||
|
o.setWebsite_url(getDecodedUrl(firstValue(CORGANIZATION_WEBSITEURL, p)));
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String asZenodoCommunity(final Concept c) {
|
||||||
|
return firstValue(CZENODOCOMMUNITY_ID, c.getParams());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<SubCommunity> asSubCommunities(final String communityId, final String parent, final String category, final List<Concept> concepts) {
|
||||||
|
final List<SubCommunity> list = new ArrayList<>();
|
||||||
|
for (final Concept c : concepts) {
|
||||||
|
final SubCommunity sc = new SubCommunity();
|
||||||
|
sc.setSubCommunityId(c.getId());
|
||||||
|
sc.setCommunityId(communityId);
|
||||||
|
sc.setParent(parent);
|
||||||
|
sc.setCategory(category);
|
||||||
|
sc.setLabel(c.getLabel());
|
||||||
|
sc.setParams(c.getParams());
|
||||||
|
sc.setClaim(c.isClaim());
|
||||||
|
sc.setBrowsable(false);
|
||||||
|
list.add(sc);
|
||||||
|
list.addAll(asSubCommunities(communityId, c.getId(), category, c.getConcepts()));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String findNamespaceForECProject(final String code) {
|
||||||
|
final List<String> list =
|
||||||
|
jdbcTemplate.queryForList("SELECT substr(id, 1, 12) from projects where code = ? and id like 'corda%'", String.class, code);
|
||||||
|
return list.isEmpty() ? null : list.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getDecodedUrl(final String encoded_url) {
|
||||||
|
if (encoded_url == null || encoded_url.startsWith("http")) { return encoded_url; }
|
||||||
|
try {
|
||||||
|
return new String(Base64.getDecoder().decode(encoded_url));
|
||||||
|
} catch (final Exception e) {
|
||||||
|
log.warn("Invalid base64: " + encoded_url);
|
||||||
|
return encoded_url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> splitValues(final Stream<String> stream, final String separator) {
|
||||||
|
return stream.map(s -> s.split(separator))
|
||||||
|
.map(Arrays::asList)
|
||||||
|
.flatMap(List::stream)
|
||||||
|
.filter(StringUtils::isNotBlank)
|
||||||
|
.map(StringUtils::trim)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String firstValue(final String name, final List<Param> params) {
|
||||||
|
return asValues(name, params).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String asCsv(final String name, final List<Param> params) {
|
||||||
|
return asValues(name, params).collect(Collectors.joining(CSV_DELIMITER));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Stream<String> asValues(final String name, final List<Param> params) {
|
||||||
|
return params == null ? Stream.empty()
|
||||||
|
: params.stream()
|
||||||
|
.filter(p -> p != null)
|
||||||
|
.filter(p -> StringUtils.isNotBlank(p.getName()))
|
||||||
|
.filter(p -> p.getName().trim().equals(name.trim()))
|
||||||
|
.map(Param::getValue)
|
||||||
|
.map(StringUtils::trim)
|
||||||
|
.distinct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DbOrganizationRepository getDbOrganizationRepository() {
|
||||||
|
return dbOrganizationRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setDbOrganizationRepository(final DbOrganizationRepository dbOrganizationRepository) {
|
||||||
|
this.dbOrganizationRepository = dbOrganizationRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CommunityService getService() {
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setService(final CommunityService service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected JdbcTemplate getJdbcTemplate() {
|
||||||
|
return jdbcTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setJdbcTemplate(final JdbcTemplate jdbcTemplate) {
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,280 @@
|
||||||
|
package eu.dnetlib.openaire.community.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Convert;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EnumType;
|
||||||
|
import javax.persistence.Enumerated;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Type;
|
||||||
|
import org.hibernate.annotations.TypeDef;
|
||||||
|
import org.hibernate.annotations.TypeDefs;
|
||||||
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
|
import org.springframework.data.annotation.LastModifiedDate;
|
||||||
|
|
||||||
|
import com.vladmihalcea.hibernate.type.array.StringArrayType;
|
||||||
|
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
|
||||||
|
import com.vladmihalcea.hibernate.type.json.JsonStringType;
|
||||||
|
|
||||||
|
import eu.dnetlib.openaire.community.utils.CommunityClaimTypeConverter;
|
||||||
|
import eu.dnetlib.openaire.community.utils.CommunityMembershipTypeConverter;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.CommunityClaimType;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.CommunityMembershipType;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.CommunityStatus;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.CommunityType;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionCriteria;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "communities")
|
||||||
|
@TypeDefs({
|
||||||
|
@TypeDef(name = "string-array", typeClass = StringArrayType.class),
|
||||||
|
@TypeDef(name = "json", typeClass = JsonStringType.class),
|
||||||
|
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
|
||||||
|
})
|
||||||
|
public class DbCommunity implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 4315597783109726539L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Column(name = "name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "shortname")
|
||||||
|
private String shortName;
|
||||||
|
|
||||||
|
@Column(name = "description")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column(name = "status")
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private CommunityStatus status = CommunityStatus.hidden;
|
||||||
|
|
||||||
|
@Column(name = "membership")
|
||||||
|
@Convert(converter = CommunityMembershipTypeConverter.class)
|
||||||
|
private CommunityMembershipType membership = CommunityMembershipType.byInvitation;
|
||||||
|
|
||||||
|
@Column(name = "type")
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private CommunityType type;
|
||||||
|
|
||||||
|
@Column(name = "claim")
|
||||||
|
@Convert(converter = CommunityClaimTypeConverter.class)
|
||||||
|
private CommunityClaimType claim;
|
||||||
|
|
||||||
|
@Type(type = "string-array")
|
||||||
|
@Column(name = "subjects", columnDefinition = "text[]")
|
||||||
|
private String[] subjects;
|
||||||
|
|
||||||
|
@Type(type = "string-array")
|
||||||
|
@Column(name = "fos", columnDefinition = "text[]")
|
||||||
|
private String[] fos;
|
||||||
|
|
||||||
|
@Type(type = "string-array")
|
||||||
|
@Column(name = "sdg", columnDefinition = "text[]")
|
||||||
|
private String[] sdg;
|
||||||
|
|
||||||
|
@Type(type = "jsonb")
|
||||||
|
@Column(name = "adv_constraints")
|
||||||
|
private SelectionCriteria advancedConstraints;
|
||||||
|
|
||||||
|
@Type(type = "jsonb")
|
||||||
|
@Column(name = "remove_constraints")
|
||||||
|
private SelectionCriteria removeConstraints;
|
||||||
|
|
||||||
|
@Column(name = "main_zenodo_community")
|
||||||
|
private String mainZenodoCommunity;
|
||||||
|
|
||||||
|
@Type(type = "string-array")
|
||||||
|
@Column(name = "other_zenodo_communities", columnDefinition = "text[]")
|
||||||
|
private String[] otherZenodoCommunities;
|
||||||
|
|
||||||
|
@CreatedDate
|
||||||
|
@Column(name = "creation_date")
|
||||||
|
private LocalDateTime creationDate;
|
||||||
|
|
||||||
|
@LastModifiedDate
|
||||||
|
@Column(name = "last_update")
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private LocalDateTime lastUpdateDate;
|
||||||
|
|
||||||
|
@Column(name = "logo_url")
|
||||||
|
private String logoUrl;
|
||||||
|
|
||||||
|
@Type(type = "string-array")
|
||||||
|
@Column(name = "suggested_acknowledgements", columnDefinition = "text[]")
|
||||||
|
private String[] suggestedAcknowledgements;
|
||||||
|
|
||||||
|
@Column(name = "plan")
|
||||||
|
private String plan;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(final String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(final String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShortName() {
|
||||||
|
return shortName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShortName(final String shortName) {
|
||||||
|
this.shortName = shortName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(final String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommunityStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(final CommunityStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommunityMembershipType getMembership() {
|
||||||
|
return membership;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMembership(final CommunityMembershipType membership) {
|
||||||
|
this.membership = membership;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommunityType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(final CommunityType type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommunityClaimType getClaim() {
|
||||||
|
return claim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClaim(final CommunityClaimType claim) {
|
||||||
|
this.claim = claim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getSubjects() {
|
||||||
|
return subjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubjects(final String[] subjects) {
|
||||||
|
this.subjects = subjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getFos() {
|
||||||
|
return fos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFos(final String[] fos) {
|
||||||
|
this.fos = fos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getSdg() {
|
||||||
|
return sdg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSdg(final String[] sdg) {
|
||||||
|
this.sdg = sdg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SelectionCriteria getAdvancedConstraints() {
|
||||||
|
return advancedConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAdvancedConstraints(final SelectionCriteria advancedConstraints) {
|
||||||
|
this.advancedConstraints = advancedConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SelectionCriteria getRemoveConstraints() {
|
||||||
|
return removeConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemoveConstraints(final SelectionCriteria removeConstraints) {
|
||||||
|
this.removeConstraints = removeConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMainZenodoCommunity() {
|
||||||
|
return mainZenodoCommunity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMainZenodoCommunity(final String mainZenodoCommunity) {
|
||||||
|
this.mainZenodoCommunity = mainZenodoCommunity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getOtherZenodoCommunities() {
|
||||||
|
return otherZenodoCommunities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOtherZenodoCommunities(final String[] otherZenodoCommunities) {
|
||||||
|
this.otherZenodoCommunities = otherZenodoCommunities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getCreationDate() {
|
||||||
|
return creationDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreationDate(final LocalDateTime creationDate) {
|
||||||
|
this.creationDate = creationDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getLastUpdateDate() {
|
||||||
|
return lastUpdateDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdateDate(final LocalDateTime lastUpdateDate) {
|
||||||
|
this.lastUpdateDate = lastUpdateDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLogoUrl() {
|
||||||
|
return logoUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogoUrl(final String logoUrl) {
|
||||||
|
this.logoUrl = logoUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getSuggestedAcknowledgements() {
|
||||||
|
return suggestedAcknowledgements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSuggestedAcknowledgements(final String[] suggestedAcknowledgements) {
|
||||||
|
this.suggestedAcknowledgements = suggestedAcknowledgements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlan() {
|
||||||
|
return plan;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlan(final String plan) {
|
||||||
|
this.plan = plan;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,101 @@
|
||||||
|
package eu.dnetlib.openaire.community.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.IdClass;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Type;
|
||||||
|
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionCriteria;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "community_datasources")
|
||||||
|
@IdClass(DbDatasourcePK.class)
|
||||||
|
public class DbDatasource implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -8782576185861694228L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "community")
|
||||||
|
private String community;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "ds_id")
|
||||||
|
private String dsId;
|
||||||
|
|
||||||
|
@Column(name = "ds_name")
|
||||||
|
private String dsName;
|
||||||
|
|
||||||
|
@Column(name = "ds_officialname")
|
||||||
|
private String dsOfficialName;
|
||||||
|
|
||||||
|
@Column(name = "enabled")
|
||||||
|
private Boolean enabled;
|
||||||
|
|
||||||
|
@Type(type = "jsonb")
|
||||||
|
@Column(name = "constraints")
|
||||||
|
private SelectionCriteria constraints;
|
||||||
|
|
||||||
|
public DbDatasource() {}
|
||||||
|
|
||||||
|
public DbDatasource(final String community, final String dsId, final String dsName, final String dsOfficialName, final SelectionCriteria constraints) {
|
||||||
|
this.community = community;
|
||||||
|
this.dsId = dsId;
|
||||||
|
this.dsName = dsName;
|
||||||
|
this.dsOfficialName = dsOfficialName;
|
||||||
|
this.constraints = constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommunity() {
|
||||||
|
return community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCommunity(final String community) {
|
||||||
|
this.community = community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDsId() {
|
||||||
|
return dsId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDsId(final String dsId) {
|
||||||
|
this.dsId = dsId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDsName() {
|
||||||
|
return dsName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDsName(final String dsName) {
|
||||||
|
this.dsName = dsName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDsOfficialName() {
|
||||||
|
return dsOfficialName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDsOfficialName(final String dsOfficialName) {
|
||||||
|
this.dsOfficialName = dsOfficialName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(final Boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SelectionCriteria getConstraints() {
|
||||||
|
return constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConstraints(final SelectionCriteria constraints) {
|
||||||
|
this.constraints = constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package eu.dnetlib.openaire.community.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class DbDatasourcePK implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -8073510491611213955L;
|
||||||
|
|
||||||
|
private String community;
|
||||||
|
|
||||||
|
private String dsId;
|
||||||
|
|
||||||
|
public DbDatasourcePK() {}
|
||||||
|
|
||||||
|
public DbDatasourcePK(final String community, final String dsId) {
|
||||||
|
this.community = community;
|
||||||
|
this.dsId = dsId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommunity() {
|
||||||
|
return community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCommunity(final String community) {
|
||||||
|
this.community = community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDsId() {
|
||||||
|
return dsId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDsId(final String dsId) {
|
||||||
|
this.dsId = dsId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(community, dsId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object obj) {
|
||||||
|
if (this == obj) { return true; }
|
||||||
|
if (!(obj instanceof DbDatasourcePK)) { return false; }
|
||||||
|
final DbDatasourcePK other = (DbDatasourcePK) obj;
|
||||||
|
return Objects.equals(community, other.community) && Objects.equals(dsId, other.dsId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("CommunityDatasourcePK [community=%s, dsId=%s]", community, dsId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package eu.dnetlib.openaire.community.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.IdClass;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "community_orgs")
|
||||||
|
@IdClass(DbOrganizationPK.class)
|
||||||
|
public class DbOrganization implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -602114117980437763L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "community")
|
||||||
|
private String community;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "org_id")
|
||||||
|
private String orgId;
|
||||||
|
|
||||||
|
public DbOrganization() {}
|
||||||
|
|
||||||
|
public DbOrganization(final String community, final String orgId) {
|
||||||
|
this.community = community;
|
||||||
|
this.orgId = orgId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommunity() {
|
||||||
|
return community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCommunity(final String community) {
|
||||||
|
this.community = community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrgId() {
|
||||||
|
return orgId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrgId(final String orgId) {
|
||||||
|
this.orgId = orgId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("DbOrganization [community=%s, orgId=%s]", community, orgId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package eu.dnetlib.openaire.community.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class DbOrganizationPK implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -6720182815397534837L;
|
||||||
|
|
||||||
|
private String community;
|
||||||
|
|
||||||
|
private String orgId;
|
||||||
|
|
||||||
|
public DbOrganizationPK() {}
|
||||||
|
|
||||||
|
public DbOrganizationPK(final String community, final String orgId) {
|
||||||
|
this.community = community;
|
||||||
|
this.orgId = orgId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommunity() {
|
||||||
|
return community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCommunity(final String community) {
|
||||||
|
this.community = community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrgId() {
|
||||||
|
return orgId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrgId(final String orgId) {
|
||||||
|
this.orgId = orgId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(community, orgId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object obj) {
|
||||||
|
if (this == obj) { return true; }
|
||||||
|
if (!(obj instanceof DbDatasourcePK)) { return false; }
|
||||||
|
final DbOrganizationPK other = (DbOrganizationPK) obj;
|
||||||
|
return Objects.equals(community, other.community) && Objects.equals(orgId, other.orgId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("CommunityOrgPK [community=%s, orgId=%s]", community, orgId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,113 @@
|
||||||
|
package eu.dnetlib.openaire.community.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.IdClass;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "community_projects")
|
||||||
|
@IdClass(DbProjectPK.class)
|
||||||
|
public class DbProject implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1649065971750517925L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "community")
|
||||||
|
private String community;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "project_id")
|
||||||
|
private String projectId;
|
||||||
|
|
||||||
|
@Column(name = "project_code")
|
||||||
|
private String projectCode;
|
||||||
|
|
||||||
|
@Column(name = "project_name")
|
||||||
|
private String projectName;
|
||||||
|
|
||||||
|
@Column(name = "project_acronym")
|
||||||
|
private String projectAcronym;
|
||||||
|
|
||||||
|
@Column(name = "project_funder")
|
||||||
|
private String projectFunder;
|
||||||
|
|
||||||
|
@CreatedDate
|
||||||
|
@Column(name = "available_since")
|
||||||
|
private LocalDate availableSince;
|
||||||
|
|
||||||
|
public DbProject() {}
|
||||||
|
|
||||||
|
public DbProject(final String community, final String projectId, final String projectCode, final String projectName, final String projectAcronym,
|
||||||
|
final String projectFunder, final LocalDate availableSince) {
|
||||||
|
this.community = community;
|
||||||
|
this.projectId = projectId;
|
||||||
|
this.projectCode = projectCode;
|
||||||
|
this.projectName = projectName;
|
||||||
|
this.projectAcronym = projectAcronym;
|
||||||
|
this.projectFunder = projectFunder;
|
||||||
|
this.availableSince = availableSince;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommunity() {
|
||||||
|
return community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCommunity(final String community) {
|
||||||
|
this.community = community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectId() {
|
||||||
|
return projectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectId(final String projectId) {
|
||||||
|
this.projectId = projectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectCode() {
|
||||||
|
return projectCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectCode(final String projectCode) {
|
||||||
|
this.projectCode = projectCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectName() {
|
||||||
|
return projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectName(final String projectName) {
|
||||||
|
this.projectName = projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectAcronym() {
|
||||||
|
return projectAcronym;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectAcronym(final String projectAcronym) {
|
||||||
|
this.projectAcronym = projectAcronym;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectFunder() {
|
||||||
|
return projectFunder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectFunder(final String projectFunder) {
|
||||||
|
this.projectFunder = projectFunder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getAvailableSince() {
|
||||||
|
return availableSince;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAvailableSince(final LocalDate availableSince) {
|
||||||
|
this.availableSince = availableSince;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package eu.dnetlib.openaire.community.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class DbProjectPK implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -4236577148534835803L;
|
||||||
|
|
||||||
|
private String community;
|
||||||
|
|
||||||
|
private String projectId;
|
||||||
|
|
||||||
|
public DbProjectPK() {}
|
||||||
|
|
||||||
|
public DbProjectPK(final String community, final String projectId) {
|
||||||
|
this.community = community;
|
||||||
|
this.projectId = projectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommunity() {
|
||||||
|
return community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCommunity(final String community) {
|
||||||
|
this.community = community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectId() {
|
||||||
|
return projectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectId(final String projectId) {
|
||||||
|
this.projectId = projectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(community, projectId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object obj) {
|
||||||
|
if (this == obj) { return true; }
|
||||||
|
if (!(obj instanceof DbProjectPK)) { return false; }
|
||||||
|
final DbProjectPK other = (DbProjectPK) obj;
|
||||||
|
return Objects.equals(community, other.community) && Objects.equals(projectId, other.projectId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("CommunityProjectPK [community=%s, projectId=%s]", community, projectId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,122 @@
|
||||||
|
package eu.dnetlib.openaire.community.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Type;
|
||||||
|
import org.hibernate.annotations.TypeDef;
|
||||||
|
import org.hibernate.annotations.TypeDefs;
|
||||||
|
|
||||||
|
import com.vladmihalcea.hibernate.type.array.StringArrayType;
|
||||||
|
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
|
||||||
|
import com.vladmihalcea.hibernate.type.json.JsonStringType;
|
||||||
|
|
||||||
|
import eu.dnetlib.openaire.exporter.model.context.Param;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "community_subs")
|
||||||
|
@TypeDefs({
|
||||||
|
@TypeDef(name = "string-array", typeClass = StringArrayType.class),
|
||||||
|
@TypeDef(name = "json", typeClass = JsonStringType.class),
|
||||||
|
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
|
||||||
|
})
|
||||||
|
public class DbSubCommunity implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 7104936574383307358L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "sub_id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Column(name = "community")
|
||||||
|
private String community;
|
||||||
|
|
||||||
|
@Column(name = "label")
|
||||||
|
private String label;
|
||||||
|
|
||||||
|
@Column(name = "category")
|
||||||
|
private String category;
|
||||||
|
|
||||||
|
@Type(type = "jsonb")
|
||||||
|
@Column(name = "params")
|
||||||
|
private List<Param> params = new ArrayList<>();
|
||||||
|
|
||||||
|
@Column(name = "parent")
|
||||||
|
private String parent;
|
||||||
|
|
||||||
|
@Column(name = "claim")
|
||||||
|
private boolean claim = false;
|
||||||
|
|
||||||
|
@Column(name = "browsable")
|
||||||
|
private boolean browsable = false;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(final String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommunity() {
|
||||||
|
return community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCommunity(final String community) {
|
||||||
|
this.community = community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(final String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategory(final String category) {
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Param> getParams() {
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParams(final List<Param> params) {
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParent(final String parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isClaim() {
|
||||||
|
return claim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClaim(final boolean claim) {
|
||||||
|
this.claim = claim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBrowsable() {
|
||||||
|
return browsable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBrowsable(final boolean browsable) {
|
||||||
|
this.browsable = browsable;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
package eu.dnetlib.openaire.community.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.IdClass;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "community_support_orgs")
|
||||||
|
@IdClass(DbSupportOrgPK.class)
|
||||||
|
public class DbSupportOrg implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1308759097276753411L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "community")
|
||||||
|
private String community;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "org_name")
|
||||||
|
private String orgName;
|
||||||
|
|
||||||
|
@Column(name = "org_url")
|
||||||
|
private String orgUrl;
|
||||||
|
|
||||||
|
@Column(name = "org_logourl")
|
||||||
|
private String orgLogoUrl;
|
||||||
|
|
||||||
|
public String getCommunity() {
|
||||||
|
return community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCommunity(final String community) {
|
||||||
|
this.community = community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrgName() {
|
||||||
|
return orgName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrgName(final String orgName) {
|
||||||
|
this.orgName = orgName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrgUrl() {
|
||||||
|
return orgUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrgUrl(final String orgUrl) {
|
||||||
|
this.orgUrl = orgUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrgLogoUrl() {
|
||||||
|
return orgLogoUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrgLogoUrl(final String orgLogoUrl) {
|
||||||
|
this.orgLogoUrl = orgLogoUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package eu.dnetlib.openaire.community.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class DbSupportOrgPK implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -4117154543803798310L;
|
||||||
|
|
||||||
|
private String community;
|
||||||
|
|
||||||
|
private String orgName;
|
||||||
|
|
||||||
|
public DbSupportOrgPK() {}
|
||||||
|
|
||||||
|
public DbSupportOrgPK(final String community, final String orgName) {
|
||||||
|
this.community = community;
|
||||||
|
this.orgName = orgName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommunity() {
|
||||||
|
return community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCommunity(final String community) {
|
||||||
|
this.community = community;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrgName() {
|
||||||
|
return orgName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrgName(final String orgName) {
|
||||||
|
this.orgName = orgName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(community, orgName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object obj) {
|
||||||
|
if (this == obj) { return true; }
|
||||||
|
if (!(obj instanceof DbSupportOrgPK)) { return false; }
|
||||||
|
final DbSupportOrgPK other = (DbSupportOrgPK) obj;
|
||||||
|
return Objects.equals(community, other.community) && Objects.equals(orgName, other.orgName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("CommunitySupportOrgPK [community=%s, orgName=%s]", community, orgName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package eu.dnetlib.openaire.community.repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
|
import eu.dnetlib.openaire.community.model.DbCommunity;
|
||||||
|
|
||||||
|
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
||||||
|
public interface DbCommunityRepository extends JpaRepository<DbCommunity, String> {
|
||||||
|
|
||||||
|
@Query(value = "select id from communities where ?1 = ANY(array_append(other_zenodo_communities, main_zenodo_community))", nativeQuery = true)
|
||||||
|
List<String> findByZenodoId(String zenodoId);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package eu.dnetlib.openaire.community.repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import eu.dnetlib.openaire.community.model.DbDatasource;
|
||||||
|
import eu.dnetlib.openaire.community.model.DbDatasourcePK;
|
||||||
|
|
||||||
|
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
||||||
|
public interface DbDatasourceRepository extends JpaRepository<DbDatasource, DbDatasourcePK> {
|
||||||
|
|
||||||
|
List<DbDatasource> findByCommunity(String community);
|
||||||
|
|
||||||
|
void deleteByCommunity(String id);
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package eu.dnetlib.openaire.community.repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import eu.dnetlib.openaire.community.model.DbOrganization;
|
||||||
|
import eu.dnetlib.openaire.community.model.DbOrganizationPK;
|
||||||
|
|
||||||
|
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
||||||
|
public interface DbOrganizationRepository extends JpaRepository<DbOrganization, DbOrganizationPK> {
|
||||||
|
|
||||||
|
List<DbOrganization> findByCommunity(String community);
|
||||||
|
|
||||||
|
void deleteByCommunity(String id);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package eu.dnetlib.openaire.community.repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
|
import eu.dnetlib.openaire.community.model.DbProject;
|
||||||
|
import eu.dnetlib.openaire.community.model.DbProjectPK;
|
||||||
|
|
||||||
|
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
||||||
|
public interface DbProjectRepository extends JpaRepository<DbProject, DbProjectPK>, JpaSpecificationExecutor<DbProject> {
|
||||||
|
|
||||||
|
Page<DbProject> findByCommunity(String community, Pageable page);
|
||||||
|
|
||||||
|
void deleteByCommunity(String id);
|
||||||
|
|
||||||
|
@Query(value = "select distinct project_funder from community_projects where community = ?1 order by project_funder", nativeQuery = true)
|
||||||
|
List<String> findFundersByCommunity(String id);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package eu.dnetlib.openaire.community.repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import eu.dnetlib.openaire.community.model.DbSubCommunity;
|
||||||
|
|
||||||
|
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
||||||
|
public interface DbSubCommunityRepository extends JpaRepository<DbSubCommunity, String> {
|
||||||
|
|
||||||
|
List<DbSubCommunity> findByCommunity(String community);
|
||||||
|
|
||||||
|
List<DbSubCommunity> findByCommunityAndParent(String community, String parent);
|
||||||
|
|
||||||
|
void deleteByCommunity(String id);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package eu.dnetlib.openaire.community.repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import eu.dnetlib.openaire.community.model.DbSupportOrg;
|
||||||
|
import eu.dnetlib.openaire.community.model.DbSupportOrgPK;
|
||||||
|
|
||||||
|
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
||||||
|
public interface DbSupportOrgRepository extends JpaRepository<DbSupportOrg, DbSupportOrgPK> {
|
||||||
|
|
||||||
|
List<DbSupportOrg> findByCommunity(String community);
|
||||||
|
|
||||||
|
void deleteByCommunity(String id);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package eu.dnetlib.openaire.community.utils;
|
||||||
|
|
||||||
|
import javax.persistence.AttributeConverter;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.CommunityClaimType;
|
||||||
|
|
||||||
|
public class CommunityClaimTypeConverter implements AttributeConverter<CommunityClaimType, String> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String convertToDatabaseColumn(final CommunityClaimType attribute) {
|
||||||
|
if (attribute == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return attribute.getDescription();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommunityClaimType convertToEntityAttribute(final String dbData) {
|
||||||
|
if (StringUtils.isBlank(dbData)) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return CommunityClaimType.fromDescription(dbData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,301 @@
|
||||||
|
package eu.dnetlib.openaire.community.utils;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import eu.dnetlib.openaire.community.importer.CommunityImporterService;
|
||||||
|
import eu.dnetlib.openaire.community.model.DbCommunity;
|
||||||
|
import eu.dnetlib.openaire.community.model.DbDatasource;
|
||||||
|
import eu.dnetlib.openaire.community.model.DbProject;
|
||||||
|
import eu.dnetlib.openaire.community.model.DbSubCommunity;
|
||||||
|
import eu.dnetlib.openaire.community.model.DbSupportOrg;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.CommunityDetails;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.CommunityOrganization;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.CommunityProject;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.CommunityWritableProperties;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.SubCommunity;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.context.IISConfigurationEntry;
|
||||||
|
|
||||||
|
public class CommunityMappingUtils {
|
||||||
|
|
||||||
|
public final static String PIPE_SEPARATOR = "||";
|
||||||
|
|
||||||
|
private static final List<String> DATE_PATTERN = Lists.newArrayList("yyyy-MM-dd'T'hh:mm:ss", "yyyy-MM-dd'T'hh:mm:ssXXX", "yyyy-MM-dd'T'hh:mm:ss+00:00");
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(CommunityMappingUtils.class);
|
||||||
|
|
||||||
|
public static CommunitySummary toCommunitySummary(final DbCommunity c) {
|
||||||
|
final CommunitySummary summary = new CommunitySummary();
|
||||||
|
populateSummary(summary, c);
|
||||||
|
return summary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DbCommunity toCommunity(final CommunityDetails details) {
|
||||||
|
final DbCommunity c = new DbCommunity();
|
||||||
|
c.setId(details.getId());
|
||||||
|
c.setName(details.getName());
|
||||||
|
c.setShortName(details.getShortName());
|
||||||
|
c.setDescription(details.getDescription());
|
||||||
|
c.setStatus(details.getStatus());
|
||||||
|
c.setLogoUrl(details.getLogoUrl());
|
||||||
|
c.setMembership(details.getMembership());
|
||||||
|
c.setType(details.getType());
|
||||||
|
c.setClaim(details.getClaim());
|
||||||
|
c.setSubjects(toStringArray(details.getSubjects()));
|
||||||
|
c.setFos(toStringArray(details.getFos()));
|
||||||
|
c.setSdg(toStringArray(details.getSdg()));
|
||||||
|
c.setAdvancedConstraints(details.getAdvancedConstraints());
|
||||||
|
c.setRemoveConstraints(details.getRemoveConstraints());
|
||||||
|
c.setMainZenodoCommunity(details.getZenodoCommunity());
|
||||||
|
c.setOtherZenodoCommunities(toStringArray(details.getOtherZenodoCommunities()));
|
||||||
|
c.setSuggestedAcknowledgements(toStringArray(details.getSuggestedAcknowledgements()));
|
||||||
|
c.setPlan(details.getPlan());
|
||||||
|
c.setCreationDate(ObjectUtils.firstNonNull(details.getCreationDate(), LocalDateTime.now()));
|
||||||
|
c.setLastUpdateDate(LocalDateTime.now());
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void populateCommunity(final DbCommunity c, final CommunityWritableProperties details) {
|
||||||
|
if (StringUtils.isNotBlank(details.getName())) {
|
||||||
|
c.setName(details.getName());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(details.getShortName())) {
|
||||||
|
c.setShortName(details.getShortName());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(details.getDescription())) {
|
||||||
|
c.setDescription(details.getDescription());
|
||||||
|
}
|
||||||
|
if (details.getStatus() != null) {
|
||||||
|
c.setStatus(details.getStatus());
|
||||||
|
}
|
||||||
|
if (details.getMembership() != null) {
|
||||||
|
c.setMembership(details.getMembership());
|
||||||
|
}
|
||||||
|
if (details.getType() != null) {
|
||||||
|
c.setType(details.getType());
|
||||||
|
}
|
||||||
|
if (details.getClaim() != null) {
|
||||||
|
c.setClaim(details.getClaim());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(details.getLogoUrl())) {
|
||||||
|
c.setLogoUrl(details.getLogoUrl());
|
||||||
|
}
|
||||||
|
if (details.getFos() != null) {
|
||||||
|
c.setFos(toStringArray(details.getFos()));
|
||||||
|
}
|
||||||
|
if (details.getSdg() != null) {
|
||||||
|
c.setSdg(toStringArray(details.getSdg()));
|
||||||
|
}
|
||||||
|
if (details.getSubjects() != null) {
|
||||||
|
c.setSubjects(toStringArray(details.getSubjects()));
|
||||||
|
}
|
||||||
|
if (details.getAdvancedConstraints() != null) {
|
||||||
|
c.setAdvancedConstraints(details.getAdvancedConstraints());
|
||||||
|
}
|
||||||
|
if (details.getRemoveConstraints() != null) {
|
||||||
|
c.setRemoveConstraints(details.getRemoveConstraints());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(details.getMainZenodoCommunity())) {
|
||||||
|
c.setMainZenodoCommunity(details.getMainZenodoCommunity());
|
||||||
|
}
|
||||||
|
if (details.getOtherZenodoCommunities() != null) {
|
||||||
|
c.setOtherZenodoCommunities(toStringArray(details.getOtherZenodoCommunities()));
|
||||||
|
}
|
||||||
|
if (details.getPlan() != null) {
|
||||||
|
c.setPlan(details.getPlan());
|
||||||
|
}
|
||||||
|
|
||||||
|
c.setLastUpdateDate(LocalDateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommunityDetails toCommunityDetails(final DbCommunity c) {
|
||||||
|
final CommunityDetails details = new CommunityDetails();
|
||||||
|
populateSummary(details, c);
|
||||||
|
details.setAdvancedConstraints(c.getAdvancedConstraints());
|
||||||
|
details.setRemoveConstraints(c.getRemoveConstraints());
|
||||||
|
details.setFos(Arrays.asList(c.getFos()));
|
||||||
|
details.setSdg(Arrays.asList(c.getSdg()));
|
||||||
|
details.setSubjects(Arrays.asList(c.getSubjects()));
|
||||||
|
details.setOtherZenodoCommunities(Arrays.asList(c.getOtherZenodoCommunities()));
|
||||||
|
details.setSuggestedAcknowledgements(Arrays.asList(c.getSuggestedAcknowledgements()));
|
||||||
|
return details;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void populateSummary(final CommunitySummary summary, final DbCommunity c) {
|
||||||
|
summary.setId(c.getId());
|
||||||
|
summary.setShortName(c.getShortName());
|
||||||
|
summary.setName(c.getName());
|
||||||
|
summary.setLastUpdateDate(c.getLastUpdateDate());
|
||||||
|
summary.setCreationDate(c.getCreationDate());
|
||||||
|
summary.setQueryId(c.getId() + PIPE_SEPARATOR + c.getShortName());
|
||||||
|
summary.setType(c.getType());
|
||||||
|
summary.setDescription(c.getDescription());
|
||||||
|
summary.setLogoUrl(c.getLogoUrl());
|
||||||
|
summary.setStatus(c.getStatus());
|
||||||
|
summary.setClaim(c.getClaim());
|
||||||
|
summary.setMembership(c.getMembership());
|
||||||
|
summary.setZenodoCommunity(c.getMainZenodoCommunity());
|
||||||
|
summary.setPlan(c.getPlan());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommunityProject toCommunityProject(final DbProject dbEntry) {
|
||||||
|
final CommunityProject cp = new CommunityProject();
|
||||||
|
cp.setCommunityId(dbEntry.getCommunity());
|
||||||
|
cp.setOpenaireId(dbEntry.getProjectId());
|
||||||
|
cp.setName(dbEntry.getProjectName());
|
||||||
|
cp.setAcronym(dbEntry.getProjectAcronym());
|
||||||
|
cp.setFunder(dbEntry.getProjectFunder());
|
||||||
|
cp.setGrantId(dbEntry.getProjectCode());
|
||||||
|
cp.setAvailableSince(dbEntry.getAvailableSince());
|
||||||
|
return cp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DbProject toDbProject(final String id, final CommunityProject project) {
|
||||||
|
final DbProject p = new DbProject();
|
||||||
|
p.setCommunity(id);
|
||||||
|
p.setProjectId(project.getOpenaireId());
|
||||||
|
p.setProjectName(project.getName());
|
||||||
|
p.setProjectAcronym(project.getAcronym());
|
||||||
|
p.setProjectCode(project.getGrantId());
|
||||||
|
p.setProjectFunder(project.getFunder());
|
||||||
|
if (project.getAvailableSince() != null) {
|
||||||
|
p.setAvailableSince(project.getAvailableSince());
|
||||||
|
} else {
|
||||||
|
p.setAvailableSince(LocalDate.now());
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommunityContentprovider toCommunityContentprovider(final DbDatasource dbEntry) {
|
||||||
|
final CommunityContentprovider ccp = new CommunityContentprovider();
|
||||||
|
ccp.setCommunityId(dbEntry.getCommunity());
|
||||||
|
ccp.setOpenaireId(dbEntry.getDsId());
|
||||||
|
ccp.setName(dbEntry.getDsName());
|
||||||
|
ccp.setOfficialname(dbEntry.getDsOfficialName());
|
||||||
|
ccp.setSelectioncriteria(dbEntry.getConstraints());
|
||||||
|
ccp.setEnabled(dbEntry.getEnabled() != null ? dbEntry.getEnabled() : true);
|
||||||
|
return ccp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DbDatasource toDbDatasource(final String id, final CommunityContentprovider provider) {
|
||||||
|
final DbDatasource ds = new DbDatasource();
|
||||||
|
ds.setCommunity(id);
|
||||||
|
ds.setDsId(provider.getOpenaireId());
|
||||||
|
ds.setDsName(provider.getName());
|
||||||
|
ds.setDsOfficialName(provider.getOfficialname());
|
||||||
|
ds.setConstraints(provider.getSelectioncriteria());
|
||||||
|
ds.setEnabled(provider.isEnabled());
|
||||||
|
return ds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommunityOrganization toCommunityOrganization(final DbSupportOrg dbEntry) {
|
||||||
|
final CommunityOrganization co = new CommunityOrganization();
|
||||||
|
co.setCommunityId(dbEntry.getCommunity());
|
||||||
|
co.setName(dbEntry.getOrgName());
|
||||||
|
co.setWebsite_url(dbEntry.getOrgUrl());
|
||||||
|
co.setLogo_url(dbEntry.getOrgLogoUrl());
|
||||||
|
return co;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DbSupportOrg toDbSupportOrg(final String id, final CommunityOrganization org) {
|
||||||
|
final DbSupportOrg dbo = new DbSupportOrg();
|
||||||
|
dbo.setCommunity(id);
|
||||||
|
dbo.setOrgName(org.getName());
|
||||||
|
dbo.setOrgUrl(org.getWebsite_url());
|
||||||
|
dbo.setOrgLogoUrl(org.getLogo_url());
|
||||||
|
return dbo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DbSubCommunity toDbSubCommunity(final String id, final SubCommunity sub) {
|
||||||
|
final DbSubCommunity dbsc = new DbSubCommunity();
|
||||||
|
dbsc.setCommunity(id);
|
||||||
|
dbsc.setId(sub.getSubCommunityId());
|
||||||
|
dbsc.setCategory(sub.getCategory());
|
||||||
|
dbsc.setLabel(sub.getLabel());
|
||||||
|
dbsc.setParams(sub.getParams());
|
||||||
|
dbsc.setParent(sub.getParent());
|
||||||
|
dbsc.setClaim(sub.isClaim());
|
||||||
|
dbsc.setBrowsable(sub.isBrowsable());
|
||||||
|
return dbsc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SubCommunity toSubCommunity(final DbSubCommunity sub) {
|
||||||
|
final SubCommunity sc = new SubCommunity();
|
||||||
|
sc.setSubCommunityId(sub.getId());
|
||||||
|
sc.setCategory(sub.getCategory());
|
||||||
|
sc.setCommunityId(sub.getCommunity());
|
||||||
|
sc.setLabel(sub.getLabel());
|
||||||
|
sc.setParams(sub.getParams());
|
||||||
|
sc.setParent(sub.getParent());
|
||||||
|
sc.setClaim(sub.isClaim());
|
||||||
|
sc.setBrowsable(sub.isBrowsable());
|
||||||
|
return sc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LocalDateTime asLocalDateTime(final String s) {
|
||||||
|
if (StringUtils.isBlank(s)) { return null; }
|
||||||
|
|
||||||
|
for (final String pattern : DATE_PATTERN) {
|
||||||
|
try {
|
||||||
|
final Date res = DateUtils.parseDate(s, pattern);
|
||||||
|
if (res != null) { return asLocalDateTime(res); }
|
||||||
|
} catch (final ParseException e) {}
|
||||||
|
}
|
||||||
|
log.warn("Invalid Date: " + s);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LocalDateTime asLocalDateTime(final Date date) {
|
||||||
|
return date.toInstant()
|
||||||
|
.atZone(ZoneId.systemDefault())
|
||||||
|
.toLocalDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String[] toStringArray(final List<String> list) {
|
||||||
|
return list != null ? list.toArray(new String[list.size()]) : new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IISConfigurationEntry asIISConfigurationEntry(final DbCommunity c) {
|
||||||
|
final IISConfigurationEntry conf = new IISConfigurationEntry();
|
||||||
|
conf.setId(c.getId());
|
||||||
|
conf.setLabel(c.getName());
|
||||||
|
conf.addParams(CommunityImporterService.CSUMMARY_DESCRIPTION, c.getDescription());
|
||||||
|
conf.addParams(CommunityImporterService.CSUMMARY_LOGOURL, c.getLogoUrl());
|
||||||
|
conf.addParams(CommunityImporterService.CSUMMARY_STATUS, c.getStatus().toString());
|
||||||
|
conf.addParams(CommunityImporterService.CSUMMARY_NAME, c.getName());
|
||||||
|
conf.addParams(CommunityImporterService.CSUMMARY_ZENODOC, c.getMainZenodoCommunity());
|
||||||
|
conf.addParams(CommunityImporterService.CPROFILE_SUBJECT, c.getSubjects());
|
||||||
|
conf.addParams(CommunityImporterService.CPROFILE_FOS, c.getFos());
|
||||||
|
conf.addParams(CommunityImporterService.CPROFILE_SDG, c.getSdg());
|
||||||
|
conf.addParams(CommunityImporterService.CPROFILE_ADVANCED_CONSTRAINT, c.getAdvancedConstraints() != null ? c.getAdvancedConstraints().toJson() : null);
|
||||||
|
conf.addParams(CommunityImporterService.CPROFILE_REMOVE_CONSTRAINT, c.getRemoveConstraints() != null ? c.getRemoveConstraints().toJson() : null);
|
||||||
|
conf.addParams(CommunityImporterService.CPROFILE_SUGGESTED_ACKNOWLEDGEMENT, c.getSuggestedAcknowledgements());
|
||||||
|
conf.addParams(CommunityImporterService.CPROFILE_CREATIONDATE, c.getCreationDate() != null ? c.getCreationDate().toString() : null);
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IISConfigurationEntry asIISConfigurationEntry(final DbSubCommunity subc) {
|
||||||
|
final IISConfigurationEntry conf = new IISConfigurationEntry();
|
||||||
|
conf.setId(subc.getId());
|
||||||
|
conf.setLabel(subc.getLabel());
|
||||||
|
if (subc.getParams() != null) {
|
||||||
|
conf.getParams().addAll(subc.getParams());
|
||||||
|
}
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package eu.dnetlib.openaire.community.utils;
|
||||||
|
|
||||||
|
import javax.persistence.AttributeConverter;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.CommunityMembershipType;
|
||||||
|
|
||||||
|
public class CommunityMembershipTypeConverter implements AttributeConverter<CommunityMembershipType, String> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String convertToDatabaseColumn(final CommunityMembershipType attribute) {
|
||||||
|
if (attribute == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return attribute.getDescription();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommunityMembershipType convertToEntityAttribute(final String dbData) {
|
||||||
|
if (StringUtils.isBlank(dbData)) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return CommunityMembershipType.fromDescription(dbData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,8 +1,13 @@
|
||||||
package eu.dnetlib.openaire.context;
|
package eu.dnetlib.openaire.context;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
@ -12,10 +17,16 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import eu.dnetlib.openaire.exporter.exceptions.ContextException;
|
import eu.dnetlib.openaire.common.AbstractExporterController;
|
||||||
|
import eu.dnetlib.openaire.community.CommunityService;
|
||||||
|
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
|
||||||
|
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.CommunityType;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.SubCommunity;
|
||||||
import eu.dnetlib.openaire.exporter.model.context.CategorySummary;
|
import eu.dnetlib.openaire.exporter.model.context.CategorySummary;
|
||||||
import eu.dnetlib.openaire.exporter.model.context.ConceptSummary;
|
import eu.dnetlib.openaire.exporter.model.context.ConceptSummary;
|
||||||
import eu.dnetlib.openaire.exporter.model.context.ContextSummary;
|
import eu.dnetlib.openaire.exporter.model.context.ContextSummary;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.context.IISConfigurationEntry;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||||
|
@ -25,12 +36,14 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@CrossOrigin(origins = {
|
@CrossOrigin(origins = {
|
||||||
"*"
|
"*"
|
||||||
})
|
})
|
||||||
@ConditionalOnProperty(value = "openaire.exporter.enable.context", havingValue = "true")
|
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
||||||
@Tag(name = "OpenAIRE Context API", description = "the OpenAIRE Context API")
|
@Tag(name = "OpenAIRE Context API", description = "the OpenAIRE Context API")
|
||||||
public class ContextApiController {
|
public class ContextApiController extends AbstractExporterController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ContextApiCore contextApiCore;
|
private CommunityService communityService;
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(ContextApiController.class);
|
||||||
|
|
||||||
@RequestMapping(value = "/contexts", produces = {
|
@RequestMapping(value = "/contexts", produces = {
|
||||||
"application/json"
|
"application/json"
|
||||||
|
@ -38,10 +51,28 @@ public class ContextApiController {
|
||||||
@Operation(summary = "list brief information about all the context profiles", description = "list brief information about all the context profiles")
|
@Operation(summary = "list brief information about all the context profiles", description = "list brief information about all the context profiles")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "not found"),
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public List<ContextSummary> listContexts(@RequestParam(required = false, defaultValue = "") final List<String> type) throws ContextException {
|
public List<ContextSummary> listContexts(@RequestParam(required = false) final Set<CommunityType> type) throws CommunityException {
|
||||||
return contextApiCore.listContexts(type);
|
try {
|
||||||
|
return communityService.listCommunities()
|
||||||
|
.stream()
|
||||||
|
.filter(c -> type == null || type.contains(c.getType()))
|
||||||
|
.map(c -> {
|
||||||
|
final ContextSummary ctx = new ContextSummary();
|
||||||
|
ctx.setId(c.getId());
|
||||||
|
ctx.setLabel(c.getName());
|
||||||
|
ctx.setStatus(c.getStatus().toString());
|
||||||
|
ctx.setType(c.getType().toString());
|
||||||
|
return ctx;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/context/{contextId}", produces = {
|
@RequestMapping(value = "/context/{contextId}", produces = {
|
||||||
|
@ -50,14 +81,52 @@ public class ContextApiController {
|
||||||
@Operation(summary = "list the categories defined within a context", description = "list the categories defined within a context")
|
@Operation(summary = "list the categories defined within a context", description = "list the categories defined within a context")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "not found"),
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public List<CategorySummary> listCategories(
|
public List<CategorySummary> listCategories(
|
||||||
@PathVariable final String contextId,
|
@PathVariable final String contextId,
|
||||||
@RequestParam(required = false, defaultValue = "false") final Boolean all) throws ContextException {
|
@RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException {
|
||||||
|
|
||||||
final Boolean allFilter = Optional.ofNullable(all).orElse(false);
|
try {
|
||||||
return contextApiCore.listCategories(contextId, allFilter);
|
return communityService.getSubCommunities(contextId)
|
||||||
|
.stream()
|
||||||
|
.filter(sc -> all || sc.isClaim())
|
||||||
|
.map(sc -> {
|
||||||
|
final String[] parts = StringUtils.split(sc.getSubCommunityId(), "::");
|
||||||
|
if (parts.length < 3) { throw new RuntimeException("Invalid conceptId (It should have 3 (or more) parts): " + sc.getSubCommunityId()); }
|
||||||
|
final CategorySummary cat = new CategorySummary();
|
||||||
|
cat.setId(parts[0] + "::" + parts[1]);
|
||||||
|
cat.setLabel(sc.getCategory());
|
||||||
|
cat.setHasConcept(true);
|
||||||
|
return cat;
|
||||||
|
})
|
||||||
|
.distinct()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/context/iis/conf/{contextId}", produces = {
|
||||||
|
"application/json"
|
||||||
|
}, method = RequestMethod.GET)
|
||||||
|
@Operation(summary = "return a list of entries for IIS", description = "return a list of entries for IIS")
|
||||||
|
@ApiResponses(value = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "not found"),
|
||||||
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
|
})
|
||||||
|
public List<IISConfigurationEntry> getIISConfiguration(@PathVariable final String contextId) throws CommunityException {
|
||||||
|
try {
|
||||||
|
return communityService.getIISConfiguration(contextId);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/context/category/{categoryId}", produces = {
|
@RequestMapping(value = "/context/category/{categoryId}", produces = {
|
||||||
|
@ -66,14 +135,30 @@ public class ContextApiController {
|
||||||
@Operation(summary = "list the concepts defined within a category", description = "list the concepts defined within a category")
|
@Operation(summary = "list the concepts defined within a category", description = "list the concepts defined within a category")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "not found"),
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public List<ConceptSummary> listConcepts(
|
public List<ConceptSummary> listConcepts(
|
||||||
@PathVariable final String categoryId,
|
@PathVariable final String categoryId,
|
||||||
@RequestParam(required = false, defaultValue = "false") final Boolean all) throws ContextException {
|
@RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException {
|
||||||
|
try {
|
||||||
|
final String[] parts = StringUtils.split(categoryId, "::");
|
||||||
|
if (parts.length != 2) {
|
||||||
|
log.error("Invalid category id (it should have 2 parts): " + categoryId);
|
||||||
|
throw new CommunityException("Invalid category id (it should have 2 parts): " + categoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
final String contextId = parts[0];
|
||||||
|
|
||||||
|
final List<SubCommunity> list = findSubCommunities(categoryId + "::", all, contextId);
|
||||||
|
|
||||||
|
return processSubCommunities(null, list);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
|
|
||||||
final Boolean allFilter = Optional.ofNullable(all).orElse(false);
|
|
||||||
return contextApiCore.listConcepts(categoryId, allFilter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/context/category/concept/{conceptId}", produces = {
|
@RequestMapping(value = "/context/category/concept/{conceptId}", produces = {
|
||||||
|
@ -82,14 +167,53 @@ public class ContextApiController {
|
||||||
@Operation(summary = "list the concepts defined within a category", description = "list the concepts defined within a category")
|
@Operation(summary = "list the concepts defined within a category", description = "list the concepts defined within a category")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "not found"),
|
||||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||||
})
|
})
|
||||||
public List<ConceptSummary> listSubConcepts(
|
public List<ConceptSummary> listSubConcepts(
|
||||||
@PathVariable final String conceptId,
|
@PathVariable final String conceptId,
|
||||||
@RequestParam(required = false, defaultValue = "false") final Boolean all) throws ContextException {
|
@RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException {
|
||||||
|
try {
|
||||||
|
final String[] parts = StringUtils.split(conceptId, "::");
|
||||||
|
if (parts.length < 3) {
|
||||||
|
log.error("Invalid concept id (it should have 3 (or more) parts): " + conceptId);
|
||||||
|
throw new CommunityException("Invalid concept id (it should have 3 (or more) parts): " + conceptId);
|
||||||
|
}
|
||||||
|
|
||||||
final Boolean allFilter = Optional.ofNullable(all).orElse(false);
|
final String contextId = parts[0];
|
||||||
return contextApiCore.listSubConcepts(conceptId, allFilter);
|
|
||||||
|
final List<SubCommunity> list = findSubCommunities(conceptId + "::", all, contextId);
|
||||||
|
|
||||||
|
return processSubCommunities(conceptId, list);
|
||||||
|
} catch (final ResourceNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SubCommunity> findSubCommunities(final String prefix, final boolean all, final String contextId) throws CommunityException {
|
||||||
|
return communityService.getSubCommunities(contextId)
|
||||||
|
.stream()
|
||||||
|
.filter(sc -> all || sc.isClaim())
|
||||||
|
.filter(sc -> sc.getSubCommunityId().startsWith(prefix))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ConceptSummary> processSubCommunities(final String parent, final List<SubCommunity> list) {
|
||||||
|
return list.stream()
|
||||||
|
.filter(sc -> Objects.equals(sc.getParent(), parent))
|
||||||
|
.map(sc -> {
|
||||||
|
final List<ConceptSummary> childs = processSubCommunities(sc.getSubCommunityId(), list);
|
||||||
|
final ConceptSummary concept = new ConceptSummary();
|
||||||
|
concept.setId(sc.getSubCommunityId());
|
||||||
|
concept.setLabel(sc.getLabel());
|
||||||
|
concept.setHasSubConcept(!childs.isEmpty());
|
||||||
|
concept.setConcept(childs);
|
||||||
|
return concept;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,12 @@ import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import eu.dnetlib.openaire.common.ISClient;
|
import eu.dnetlib.openaire.common.ISClient;
|
||||||
import eu.dnetlib.openaire.exporter.exceptions.ContextException;
|
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
|
||||||
import eu.dnetlib.openaire.exporter.model.context.Category;
|
import eu.dnetlib.openaire.exporter.model.context.Category;
|
||||||
import eu.dnetlib.openaire.exporter.model.context.CategorySummary;
|
import eu.dnetlib.openaire.exporter.model.context.CategorySummary;
|
||||||
import eu.dnetlib.openaire.exporter.model.context.Concept;
|
import eu.dnetlib.openaire.exporter.model.context.Concept;
|
||||||
|
@ -23,8 +21,9 @@ import eu.dnetlib.openaire.exporter.model.context.ConceptSummary;
|
||||||
import eu.dnetlib.openaire.exporter.model.context.Context;
|
import eu.dnetlib.openaire.exporter.model.context.Context;
|
||||||
import eu.dnetlib.openaire.exporter.model.context.ContextSummary;
|
import eu.dnetlib.openaire.exporter.model.context.ContextSummary;
|
||||||
|
|
||||||
@Component
|
// @Component
|
||||||
@ConditionalOnProperty(value = "openaire.exporter.enable.context", havingValue = "true")
|
// @ConditionalOnProperty(value = "openaire.exporter.enable.context", havingValue = "true")
|
||||||
|
@Deprecated
|
||||||
public class ContextApiCore {
|
public class ContextApiCore {
|
||||||
|
|
||||||
private static final String SEPARATOR = "::";
|
private static final String SEPARATOR = "::";
|
||||||
|
@ -32,18 +31,24 @@ public class ContextApiCore {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISClient isClient;
|
private ISClient isClient;
|
||||||
|
|
||||||
public List<ContextSummary> listContexts(final List<String> type) throws ContextException {
|
public List<ContextSummary> listContexts(final List<String> type) throws CommunityException {
|
||||||
|
|
||||||
return getContextMap(type).values()
|
return getContextMap(type).values()
|
||||||
.stream()
|
.stream()
|
||||||
.map(c -> new ContextSummary()
|
.map(c -> new ContextSummary()
|
||||||
.setId(c.getId())
|
.setId(c.getId())
|
||||||
.setType(c.getType())
|
.setType(c.getType())
|
||||||
.setLabel(c.getLabel())
|
.setLabel(c.getLabel())
|
||||||
.setStatus(c.getParams().containsKey("status") ? c.getParams().get("status").get(0).getValue() : ""))
|
.setStatus(c.getParams()
|
||||||
|
.stream()
|
||||||
|
.filter(p -> p.getName().equals("status"))
|
||||||
|
.map(p -> p.getValue())
|
||||||
|
.findFirst()
|
||||||
|
.orElse("")))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CategorySummary> listCategories(final String contextId, final Boolean all) throws ContextException {
|
public List<CategorySummary> listCategories(final String contextId, final Boolean all) throws CommunityException {
|
||||||
final Stream<Category> categories = getContextMap().get(contextId).getCategories().values().stream();
|
final Stream<Category> categories = getContextMap().get(contextId).getCategories().values().stream();
|
||||||
return all ? asCategorySummaries(categories) : asCategorySummaries(categories.filter(Category::isClaim));
|
return all ? asCategorySummaries(categories) : asCategorySummaries(categories.filter(Category::isClaim));
|
||||||
}
|
}
|
||||||
|
@ -57,7 +62,7 @@ public class ContextApiCore {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ConceptSummary> listConcepts(final String categoryId, final Boolean all) throws ContextException {
|
public List<ConceptSummary> listConcepts(final String categoryId, final Boolean all) throws CommunityException {
|
||||||
final String contextId = StringUtils.substringBefore(categoryId, SEPARATOR);
|
final String contextId = StringUtils.substringBefore(categoryId, SEPARATOR);
|
||||||
final Stream<Concept> concepts = getContextMap().get(contextId)
|
final Stream<Concept> concepts = getContextMap().get(contextId)
|
||||||
.getCategories()
|
.getCategories()
|
||||||
|
@ -77,9 +82,9 @@ public class ContextApiCore {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ConceptSummary> listSubConcepts(final String conceptId, final Boolean all) throws ContextException {
|
public List<ConceptSummary> listSubConcepts(final String conceptId, final Boolean all) throws CommunityException {
|
||||||
final List<String> ids = Splitter.on(SEPARATOR).splitToList(conceptId);
|
final List<String> ids = Splitter.on(SEPARATOR).splitToList(conceptId);
|
||||||
if (ids.size() < 3) { throw new ContextException(""); }
|
if (ids.size() < 3) { throw new CommunityException(""); }
|
||||||
|
|
||||||
final String contextId = ids.get(0);
|
final String contextId = ids.get(0);
|
||||||
final String categoryId = contextId + SEPARATOR + ids.get(1);
|
final String categoryId = contextId + SEPARATOR + ids.get(1);
|
||||||
|
@ -105,15 +110,15 @@ public class ContextApiCore {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Context> getContextMap() throws ContextException {
|
private Map<String, Context> getContextMap() throws CommunityException {
|
||||||
return getContextMap(Lists.newArrayList());
|
return getContextMap(Lists.newArrayList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Context> getContextMap(final List<String> type) throws ContextException {
|
private Map<String, Context> getContextMap(final List<String> type) throws CommunityException {
|
||||||
try {
|
try {
|
||||||
return isClient.getContextMap(type);
|
return isClient.getContextMap(type);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
throw new ContextException(e);
|
throw new CommunityException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package eu.dnetlib.openaire.context;
|
package eu.dnetlib.openaire.context;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -11,6 +10,8 @@ import java.util.stream.Collectors;
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.time.DateUtils;
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.dom4j.Document;
|
import org.dom4j.Document;
|
||||||
import org.dom4j.DocumentException;
|
import org.dom4j.DocumentException;
|
||||||
import org.dom4j.DocumentHelper;
|
import org.dom4j.DocumentHelper;
|
||||||
|
@ -26,25 +27,31 @@ import eu.dnetlib.openaire.exporter.model.context.Context;
|
||||||
import eu.dnetlib.openaire.exporter.model.context.Param;
|
import eu.dnetlib.openaire.exporter.model.context.Param;
|
||||||
import eu.dnetlib.openaire.exporter.model.funders.FunderDetails;
|
import eu.dnetlib.openaire.exporter.model.funders.FunderDetails;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class ContextMappingUtils {
|
public class ContextMappingUtils {
|
||||||
|
|
||||||
private static final List<String> DATE_PATTERN = Lists.newArrayList("yyyy-MM-dd'T'hh:mm:ss", "yyyy-MM-dd'T'hh:mm:ssXXX", "yyyy-MM-dd'T'hh:mm:ss+00:00");
|
private static final List<String> DATE_PATTERN = Lists.newArrayList("yyyy-MM-dd'T'hh:mm:ss", "yyyy-MM-dd'T'hh:mm:ssXXX", "yyyy-MM-dd'T'hh:mm:ss+00:00");
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(ContextMappingUtils.class);
|
||||||
|
|
||||||
public static Context parseContext(final String s, final Queue<Throwable> errors) {
|
public static Context parseContext(final String s, final Queue<Throwable> errors) {
|
||||||
try {
|
try {
|
||||||
final Document doc = DocumentHelper.parseText(s);
|
final Document doc = DocumentHelper.parseText(s);
|
||||||
final Element eContext = (Element) doc.selectSingleNode("/RESOURCE_PROFILE/BODY/CONFIGURATION/context");
|
final Element eContext = (Element) doc.selectSingleNode("/RESOURCE_PROFILE/BODY/CONFIGURATION/context");
|
||||||
final String creationDate = eContext.valueOf("./param[./@name='creationdate']/text()");
|
final String creationDate = eContext.valueOf("./param[./@name='creationdate']/text()");
|
||||||
|
final String otherDate = doc.valueOf("/RESOURCE_PROFILE/HEADER/DATE_OF_CREATION/@value");
|
||||||
final Context c = new Context()
|
final Context c = new Context()
|
||||||
.setId(eContext.attributeValue("id"))
|
.setId(eContext.attributeValue("id"))
|
||||||
.setLabel(eContext.attributeValue("label"))
|
.setLabel(eContext.attributeValue("label"))
|
||||||
.setType(eContext.attributeValue("type"))
|
.setType(eContext.attributeValue("type"))
|
||||||
.setLastUpdateDate(asDate(doc.valueOf("/RESOURCE_PROFILE/HEADER/DATE_OF_CREATION/@value")))
|
.setLastUpdateDate(asDate(otherDate))
|
||||||
.setParams(parseParams(eContext))
|
.setParams(parseParams(eContext))
|
||||||
.setCategories(parseCategories(eContext));
|
.setCategories(parseCategories(eContext));
|
||||||
// the creation date will be added in the param elements of the community profile. Funders may not have it, hence the check.
|
// the creation date will be added in the param elements of the community profile. Funders may not have it, hence the check.
|
||||||
if (StringUtils.isNotBlank(creationDate)) {
|
if (StringUtils.isNotBlank(creationDate)) {
|
||||||
c.setCreationDate(asDate(creationDate));
|
c.setCreationDate(asDate(creationDate));
|
||||||
|
} else {
|
||||||
|
c.setCreationDate(asDate(otherDate));
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
} catch (final DocumentException e) {
|
} catch (final DocumentException e) {
|
||||||
|
@ -54,11 +61,15 @@ public class ContextMappingUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Date asDate(final String s) {
|
private static Date asDate(final String s) {
|
||||||
|
if (StringUtils.isBlank(s)) { return null; }
|
||||||
|
|
||||||
for (final String pattern : DATE_PATTERN) {
|
for (final String pattern : DATE_PATTERN) {
|
||||||
try {
|
try {
|
||||||
return DateUtils.parseDate(s, pattern);
|
final Date res = DateUtils.parseDate(s, pattern);
|
||||||
|
if (res != null) { return res; }
|
||||||
} catch (final ParseException e) {}
|
} catch (final ParseException e) {}
|
||||||
}
|
}
|
||||||
|
log.warn("Invalid Date: " + s);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,18 +104,12 @@ public class ContextMappingUtils {
|
||||||
return BooleanUtils.toBooleanObject(StringUtils.isNotBlank(claim) ? claim : "false");
|
return BooleanUtils.toBooleanObject(StringUtils.isNotBlank(claim) ? claim : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, List<Param>> parseParams(final Element e) {
|
private static List<Param> parseParams(final Element e) {
|
||||||
final List<Node> params = e.selectNodes("./param");
|
final List<Node> params = e.selectNodes("./param");
|
||||||
return params.stream()
|
return params.stream()
|
||||||
.map(n -> (Element) n)
|
.map(n -> (Element) n)
|
||||||
.map(p -> new Param()
|
.map(p -> new Param().setName(p.attributeValue("name")).setValue(p.getTextTrim()))
|
||||||
.setName(p.attributeValue("name"))
|
.collect(Collectors.toList());
|
||||||
.setValue(p.getTextTrim()))
|
|
||||||
.collect(Collectors.toMap(Param::getName, Lists::newArrayList, (p1, p2) -> {
|
|
||||||
final List<Param> p = new ArrayList<>(p1);
|
|
||||||
p.addAll(p2);
|
|
||||||
return p;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FunderDetails asFunderDetails(final Context c) {
|
public static FunderDetails asFunderDetails(final Context c) {
|
||||||
|
|
|
@ -36,7 +36,6 @@ import eu.dnetlib.enabling.datasources.common.DsmException;
|
||||||
import eu.dnetlib.enabling.datasources.common.DsmForbiddenException;
|
import eu.dnetlib.enabling.datasources.common.DsmForbiddenException;
|
||||||
import eu.dnetlib.enabling.datasources.common.DsmNotFoundException;
|
import eu.dnetlib.enabling.datasources.common.DsmNotFoundException;
|
||||||
import eu.dnetlib.openaire.common.ISClient;
|
import eu.dnetlib.openaire.common.ISClient;
|
||||||
import eu.dnetlib.openaire.community.CommunityClient;
|
|
||||||
import eu.dnetlib.openaire.dsm.dao.CountryTermRepository;
|
import eu.dnetlib.openaire.dsm.dao.CountryTermRepository;
|
||||||
import eu.dnetlib.openaire.dsm.dao.DatasourceDao;
|
import eu.dnetlib.openaire.dsm.dao.DatasourceDao;
|
||||||
import eu.dnetlib.openaire.dsm.dao.MongoLoggerClient;
|
import eu.dnetlib.openaire.dsm.dao.MongoLoggerClient;
|
||||||
|
@ -91,9 +90,6 @@ public class DsmCore {
|
||||||
@Autowired
|
@Autowired
|
||||||
private JdbcTemplate jdbcTemplate;
|
private JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CommunityClient communityClient;
|
|
||||||
|
|
||||||
public List<Country> listCountries() throws DsmApiException {
|
public List<Country> listCountries() throws DsmApiException {
|
||||||
final List<Country> countries = Lists.newArrayList();
|
final List<Country> countries = Lists.newArrayList();
|
||||||
final Vocabulary v = vocabularyClient.getCountries();
|
final Vocabulary v = vocabularyClient.getCountries();
|
||||||
|
@ -321,7 +317,6 @@ public class DsmCore {
|
||||||
mongoLoggerClient.dropCache();
|
mongoLoggerClient.dropCache();
|
||||||
isClient.dropCache();
|
isClient.dropCache();
|
||||||
vocabularyClient.dropCache();
|
vocabularyClient.dropCache();
|
||||||
communityClient.dropCache();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// HELPERS //////////////
|
// HELPERS //////////////
|
||||||
|
|
|
@ -25,6 +25,7 @@ management.endpoints.web.path-mapping.health = health
|
||||||
# ENABLE / DISABLE CONTROLLERS
|
# ENABLE / DISABLE CONTROLLERS
|
||||||
openaire.exporter.enable.dsm = true
|
openaire.exporter.enable.dsm = true
|
||||||
openaire.exporter.enable.community = true
|
openaire.exporter.enable.community = true
|
||||||
|
openaire.exporter.enable.community.import = false
|
||||||
openaire.exporter.enable.context = true
|
openaire.exporter.enable.context = true
|
||||||
openaire.exporter.enable.funders = false
|
openaire.exporter.enable.funders = false
|
||||||
openaire.exporter.enable.project = true
|
openaire.exporter.enable.project = true
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
services.is.protocol = http
|
||||||
services.is.host = localhost
|
services.is.host = localhost
|
||||||
services.is.port = 8280
|
services.is.port = 8280
|
||||||
services.is.protocol = http
|
|
||||||
services.is.context = app
|
services.is.context = app
|
||||||
|
|
||||||
services.is.baseurl = ${services.is.protocol}://${services.is.host}:${services.is.port}/${services.is.context}/services
|
services.is.baseurl = ${services.is.protocol}://${services.is.host}:${services.is.port}/${services.is.context}/services
|
||||||
|
|
||||||
openaire.exporter.isLookupUrl = ${services.is.baseurl}/isLookUp
|
openaire.exporter.isLookupUrl = ${services.is.baseurl}/isLookUp
|
||||||
|
@ -15,8 +16,8 @@ openaire.exporter.cxfClientConnectTimeout = 60000
|
||||||
openaire.exporter.cxfClientReceiveTimeout = 120000
|
openaire.exporter.cxfClientReceiveTimeout = 120000
|
||||||
|
|
||||||
# JDBC
|
# JDBC
|
||||||
#openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dnet_openaireplus
|
openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dnet_openaireplus
|
||||||
openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dev_openaire_8280
|
#openaire.exporter.jdbc.url = jdbc:postgresql://localhost:5432/dev_openaire_8280
|
||||||
openaire.exporter.jdbc.user = dnetapi
|
openaire.exporter.jdbc.user = dnetapi
|
||||||
openaire.exporter.jdbc.pwd = dnetPwd
|
openaire.exporter.jdbc.pwd = dnetPwd
|
||||||
openaire.exporter.jdbc.minIdle = 1
|
openaire.exporter.jdbc.minIdle = 1
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
DROP TABLE IF EXISTS community_subs;
|
||||||
|
DROP TABLE IF EXISTS community_projects;
|
||||||
|
DROP TABLE IF EXISTS community_datasources;
|
||||||
|
DROP TABLE IF EXISTS community_support_orgs;
|
||||||
|
DROP TABLE IF EXISTS community_orgs;
|
||||||
|
DROP TABLE IF EXISTS communities;
|
||||||
|
|
||||||
|
CREATE TABLE communities (
|
||||||
|
id text PRIMARY KEY,
|
||||||
|
name text NOT NULL,
|
||||||
|
shortname text NOT NULL, -- in the profile is label
|
||||||
|
description text NOT NULL DEFAULT '',
|
||||||
|
status text NOT NULL DEFAULT 'hidden', -- all, manager, hidden, members
|
||||||
|
membership text NOT NULL DEFAULT 'by-invitation', -- open, by-invitation
|
||||||
|
type text NOT NULL, -- community, ri
|
||||||
|
claim text, -- managers-only, members-only, all
|
||||||
|
subjects text[],
|
||||||
|
fos text[],
|
||||||
|
sdg text[],
|
||||||
|
adv_constraints jsonb,
|
||||||
|
remove_constraints jsonb,
|
||||||
|
main_zenodo_community text,
|
||||||
|
other_zenodo_communities text[],
|
||||||
|
creation_date timestamp NOT NULL DEFAULT now(),
|
||||||
|
last_update timestamp NOT NULL DEFAULT now(),
|
||||||
|
logo_url text,
|
||||||
|
suggested_acknowledgements text[],
|
||||||
|
plan text
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE community_projects (
|
||||||
|
community text NOT NULL REFERENCES communities(id),
|
||||||
|
project_id text NOT NULL,
|
||||||
|
project_code text NOT NULL,
|
||||||
|
project_name text NOT NULL,
|
||||||
|
project_acronym text,
|
||||||
|
project_funder text NOT NULL,
|
||||||
|
available_since date NOT NULL default now(),
|
||||||
|
PRIMARY KEY (community, project_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE community_datasources (
|
||||||
|
community text NOT NULL REFERENCES communities(id),
|
||||||
|
ds_id text NOT NULL,
|
||||||
|
ds_name text NOT NULL,
|
||||||
|
ds_officialname text NOT NULL,
|
||||||
|
enabled boolean NOT NULL DEFAULT true;
|
||||||
|
constraints jsonb,
|
||||||
|
PRIMARY KEY (community, ds_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE community_support_orgs (
|
||||||
|
community text NOT NULL REFERENCES communities(id),
|
||||||
|
org_name text NOT NULL,
|
||||||
|
org_url text NOT NULL,
|
||||||
|
org_logourl text NOT NULL,
|
||||||
|
PRIMARY KEY (community, org_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE community_orgs (
|
||||||
|
community text NOT NULL REFERENCES communities(id),
|
||||||
|
org_id text NOT NULL,
|
||||||
|
PRIMARY KEY (community, org_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE community_subs (
|
||||||
|
sub_id text NOT NULL PRIMARY KEY,
|
||||||
|
community text NOT NULL REFERENCES communities(id),
|
||||||
|
label text NOT NULL,
|
||||||
|
category text NOT NULL,
|
||||||
|
claim boolean NOT NULL DEFAULT false,
|
||||||
|
browsable boolean NOT NULL DEFAULT false,
|
||||||
|
params jsonb,
|
||||||
|
parent text REFERENCES community_subs(sub_id) -- NULL for the first level
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX community_projects_community ON community_projects(community);
|
||||||
|
CREATE INDEX community_datasources_community ON community_datasources(community);
|
||||||
|
CREATE INDEX community_support_orgs_community ON community_support_orgs(community);
|
||||||
|
CREATE INDEX community_orgs_community ON community_orgs(community);
|
||||||
|
CREATE INDEX community_subs_community ON community_subs(community);
|
||||||
|
CREATE INDEX community_subs_parent ON community_subs(parent);
|
|
@ -0,0 +1,11 @@
|
||||||
|
\copy (
|
||||||
|
SELECT
|
||||||
|
'netherlands' AS community,
|
||||||
|
'nwo_________::'||md5(substr(id, 15)) AS project_id,
|
||||||
|
code AS project_code,
|
||||||
|
title AS project_name,
|
||||||
|
acronym AS project_acronym,
|
||||||
|
'NWO' AS project_funder
|
||||||
|
FROM projects
|
||||||
|
WHERE id LIKE 'nwo\_\_\_\_\_\_\_\_\_::%'
|
||||||
|
) TO '/tmp/nwo_community_projects.csv' CSV HEADER;
|
|
@ -0,0 +1 @@
|
||||||
|
\copy community_projects FROM '/tmp/nwo_community_projects.csv' CSV HEADER;
|
|
@ -8,7 +8,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Date;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -46,7 +46,7 @@ public class CommunityApiControllerTest {
|
||||||
final CommunitySummary cs = new CommunitySummary();
|
final CommunitySummary cs = new CommunitySummary();
|
||||||
cs.setDescription("the description");
|
cs.setDescription("the description");
|
||||||
cs.setId("id1");
|
cs.setId("id1");
|
||||||
cs.setLastUpdateDate(new Date());
|
cs.setLastUpdateDate(LocalDateTime.now());
|
||||||
cs.setName("X");
|
cs.setName("X");
|
||||||
cs.setShortName("x");
|
cs.setShortName("x");
|
||||||
final List<CommunitySummary> csList = singletonList(cs);
|
final List<CommunitySummary> csList = singletonList(cs);
|
||||||
|
|
|
@ -0,0 +1,161 @@
|
||||||
|
package eu.dnetlib.openaire.community.importer;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
import eu.dnetlib.openaire.community.CommunityService;
|
||||||
|
import eu.dnetlib.openaire.community.model.DbOrganization;
|
||||||
|
import eu.dnetlib.openaire.community.repository.DbOrganizationRepository;
|
||||||
|
import eu.dnetlib.openaire.context.ContextMappingUtils;
|
||||||
|
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.SubCommunity;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.context.Context;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class CommunityImporterServiceTest {
|
||||||
|
|
||||||
|
// Class under test
|
||||||
|
private CommunityImporterService importer;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private DbOrganizationRepository dbOrganizationRepository;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private CommunityService service;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp() {
|
||||||
|
importer = new CommunityImporterService();
|
||||||
|
importer.setDbOrganizationRepository(dbOrganizationRepository);
|
||||||
|
importer.setService(service);
|
||||||
|
importer.setJdbcTemplate(jdbcTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportPropagationOrganizationsFromProfile() throws Exception {
|
||||||
|
final String profile = IOUtils.toString(getClass().getResourceAsStream("old_provision_wf.xml"), StandardCharsets.UTF_8.toString());
|
||||||
|
final List<DbOrganization> list = importer.importPropagationOrganizationsFromProfile(profile, true);
|
||||||
|
// list.forEach(System.out::println);
|
||||||
|
|
||||||
|
assertEquals(245, list.size());
|
||||||
|
assertEquals(1, list.stream().filter(o -> o.getOrgId().equals("openorgs____::9dd5545aacd3d8019e00c3f837269746")).count());
|
||||||
|
assertEquals(2, list.stream().filter(o -> o.getOrgId().equals("openorgs____::d11f981828c485cd23d93f7f24f24db1")).count());
|
||||||
|
assertEquals(14, list.stream().filter(o -> o.getCommunity().equals("beopen")).count());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
public void testImportCommunity() throws Exception {
|
||||||
|
final String profile = IOUtils.toString(getClass().getResourceAsStream("old_community_profile.xml"), StandardCharsets.UTF_8.toString());
|
||||||
|
|
||||||
|
final Queue<Throwable> errors = new LinkedList<>();
|
||||||
|
final Context context = ContextMappingUtils.parseContext(profile, errors);
|
||||||
|
assertTrue(errors.isEmpty());
|
||||||
|
|
||||||
|
Mockito.when(jdbcTemplate.queryForList(Mockito.anyString(), Mockito.any(Class.class), Mockito.anyString())).thenReturn(Arrays.asList("corda_______"));
|
||||||
|
importer.importCommunity(context);
|
||||||
|
|
||||||
|
final ArgumentCaptor<CommunityDetails> detailsCapture = ArgumentCaptor.forClass(CommunityDetails.class);
|
||||||
|
final ArgumentCaptor<CommunityProject> projectsCapture = ArgumentCaptor.forClass(CommunityProject.class);
|
||||||
|
final ArgumentCaptor<CommunityContentprovider> datasourcesCapture = ArgumentCaptor.forClass(CommunityContentprovider.class);
|
||||||
|
final ArgumentCaptor<CommunityOrganization> orgsCapture = ArgumentCaptor.forClass(CommunityOrganization.class);
|
||||||
|
final ArgumentCaptor<SubCommunity> subCommunitiesCapture = ArgumentCaptor.forClass(SubCommunity.class);
|
||||||
|
|
||||||
|
Mockito.verify(service, Mockito.times(1)).saveCommunity(detailsCapture.capture());
|
||||||
|
Mockito.verify(service, Mockito.times(1)).addCommunityProjects(Mockito.anyString(), projectsCapture.capture());
|
||||||
|
Mockito.verify(service, Mockito.times(1)).addCommunityContentProviders(Mockito.anyString(), datasourcesCapture.capture());
|
||||||
|
Mockito.verify(service, Mockito.times(1)).addCommunityOrganizations(Mockito.anyString(), orgsCapture.capture());
|
||||||
|
Mockito.verify(service, Mockito.times(1)).addSubCommunities(Mockito.anyString(), subCommunitiesCapture.capture());
|
||||||
|
|
||||||
|
final CommunityDetails details = detailsCapture.getValue();
|
||||||
|
assertEquals("egi", details.getId());
|
||||||
|
// System.out.println(details);
|
||||||
|
|
||||||
|
final List<CommunityProject> projects = projectsCapture.getAllValues();
|
||||||
|
assertEquals(83, projects.size());
|
||||||
|
// projects.forEach(System.out::println);
|
||||||
|
|
||||||
|
final List<CommunityContentprovider> datasources = datasourcesCapture.getAllValues();
|
||||||
|
assertEquals(1, datasources.size());
|
||||||
|
// datasources.forEach(System.out::println);
|
||||||
|
|
||||||
|
final List<CommunityOrganization> orgs = orgsCapture.getAllValues();
|
||||||
|
assertEquals(1, orgs.size());
|
||||||
|
// orgs.forEach(System.out::println);
|
||||||
|
|
||||||
|
final List<SubCommunity> subs = subCommunitiesCapture.getAllValues();
|
||||||
|
assertEquals(688, subs.size());
|
||||||
|
// subs.forEach(System.out::println);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
public void testImportCommunityFetFp7() throws Exception {
|
||||||
|
final String profile = IOUtils.toString(getClass().getResourceAsStream("old_community_profile_fet-fp7.xml"), StandardCharsets.UTF_8.toString());
|
||||||
|
|
||||||
|
final Queue<Throwable> errors = new LinkedList<>();
|
||||||
|
final Context context = ContextMappingUtils.parseContext(profile, errors);
|
||||||
|
assertTrue(errors.isEmpty());
|
||||||
|
|
||||||
|
// Mockito.when(jdbcTemplate.queryForList(Mockito.anyString(), Mockito.any(Class.class),
|
||||||
|
// Mockito.anyString())).thenReturn(Arrays.asList("corda_______"));
|
||||||
|
importer.importCommunity(context);
|
||||||
|
|
||||||
|
final ArgumentCaptor<CommunityDetails> detailsCapture = ArgumentCaptor.forClass(CommunityDetails.class);
|
||||||
|
final ArgumentCaptor<CommunityProject> projectsCapture = ArgumentCaptor.forClass(CommunityProject.class);
|
||||||
|
final ArgumentCaptor<CommunityContentprovider> datasourcesCapture = ArgumentCaptor.forClass(CommunityContentprovider.class);
|
||||||
|
final ArgumentCaptor<CommunityOrganization> orgsCapture = ArgumentCaptor.forClass(CommunityOrganization.class);
|
||||||
|
final ArgumentCaptor<SubCommunity> subCommunitiesCapture = ArgumentCaptor.forClass(SubCommunity.class);
|
||||||
|
|
||||||
|
Mockito.verify(service, Mockito.times(1)).saveCommunity(detailsCapture.capture());
|
||||||
|
Mockito.verify(service, Mockito.times(1)).addCommunityProjects(Mockito.anyString(), projectsCapture.capture());
|
||||||
|
Mockito.verify(service, Mockito.times(1)).addCommunityContentProviders(Mockito.anyString(), datasourcesCapture.capture());
|
||||||
|
Mockito.verify(service, Mockito.times(1)).addCommunityOrganizations(Mockito.anyString(), orgsCapture.capture());
|
||||||
|
Mockito.verify(service, Mockito.times(1)).addSubCommunities(Mockito.anyString(), subCommunitiesCapture.capture());
|
||||||
|
|
||||||
|
final CommunityDetails details = detailsCapture.getValue();
|
||||||
|
assertEquals("fet-fp7", details.getId());
|
||||||
|
// System.out.println(details);
|
||||||
|
|
||||||
|
final List<CommunityProject> projects = projectsCapture.getAllValues();
|
||||||
|
assertEquals(0, projects.size());
|
||||||
|
// projects.forEach(System.out::println);
|
||||||
|
|
||||||
|
final List<CommunityContentprovider> datasources = datasourcesCapture.getAllValues();
|
||||||
|
assertEquals(0, datasources.size());
|
||||||
|
// datasources.forEach(System.out::println);
|
||||||
|
|
||||||
|
final List<CommunityOrganization> orgs = orgsCapture.getAllValues();
|
||||||
|
assertEquals(0, orgs.size());
|
||||||
|
// orgs.forEach(System.out::println);
|
||||||
|
|
||||||
|
final List<SubCommunity> subs = subCommunitiesCapture.getAllValues();
|
||||||
|
assertEquals(151, subs.size());
|
||||||
|
subs.forEach(System.out::println);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,5 @@
|
||||||
package eu.dnetlib.openaire.exporter.exceptions;
|
package eu.dnetlib.openaire.exporter.exceptions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class CommunityException extends Exception {
|
public class CommunityException extends Exception {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,7 +11,7 @@ public class CommunityException extends Exception {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityException(final IOException e) {
|
public CommunityException(final Throwable e) {
|
||||||
super(e);
|
super(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
package eu.dnetlib.openaire.exporter.exceptions;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class ContextException extends Exception {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = -5489369676370127052L;
|
|
||||||
|
|
||||||
public ContextException(final String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContextException(final IOException e) {
|
|
||||||
super(e);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package eu.dnetlib.openaire.exporter.exceptions;
|
|
||||||
|
|
||||||
public class ContextNotFoundException extends Exception {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = -2026506752817353752L;
|
|
||||||
|
|
||||||
public ContextNotFoundException(final String msg) {
|
|
||||||
super(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContextNotFoundException(final Exception e) {
|
|
||||||
super(e);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package eu.dnetlib.openaire.exporter.model.community;
|
||||||
|
|
||||||
|
public enum CommunityClaimType {
|
||||||
|
|
||||||
|
managersOnly("managers-only"),
|
||||||
|
membersOnly("members-only"),
|
||||||
|
all("all");
|
||||||
|
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
private CommunityClaimType(final String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommunityClaimType fromDescription(final String dbData) {
|
||||||
|
for (final CommunityClaimType t : CommunityClaimType.values()) {
|
||||||
|
if (t.description.equalsIgnoreCase(dbData)) { return t; }
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -19,10 +19,6 @@ public class CommunityContentprovider {
|
||||||
@Schema(description = "the community identifier this content provider belongs to", required = true)
|
@Schema(description = "the community identifier this content provider belongs to", required = true)
|
||||||
private String communityId;
|
private String communityId;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Schema(description = "identifies this content provider within the context it belongs to", required = true)
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
@Schema(description = "content provider name", required = false)
|
@Schema(description = "content provider name", required = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ -30,6 +26,10 @@ public class CommunityContentprovider {
|
||||||
@Schema(description = "content provider official name", required = true)
|
@Schema(description = "content provider official name", required = true)
|
||||||
private String officialname;
|
private String officialname;
|
||||||
|
|
||||||
|
// @NotNull
|
||||||
|
@Schema(description = "content provider enabled for content inclusion", required = false)
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
// @NotNull
|
// @NotNull
|
||||||
@Schema(description = "content provider selection criteria", required = false)
|
@Schema(description = "content provider selection criteria", required = false)
|
||||||
private SelectionCriteria selectioncriteria;
|
private SelectionCriteria selectioncriteria;
|
||||||
|
@ -50,14 +50,6 @@ public class CommunityContentprovider {
|
||||||
this.communityId = communityId;
|
this.communityId = communityId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(final String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -74,8 +66,15 @@ public class CommunityContentprovider {
|
||||||
this.officialname = officialname;
|
this.officialname = officialname;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelectionCriteria getSelectioncriteria() {
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(final boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SelectionCriteria getSelectioncriteria() {
|
||||||
return this.selectioncriteria;
|
return this.selectioncriteria;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,11 +83,6 @@ public class CommunityContentprovider {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.format("id %s, name %s, selection criteria %s", this.id, this.name, toJson());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toJson() {
|
public String toJson() {
|
||||||
if (selectioncriteria == null) { return ""; }
|
if (selectioncriteria == null) { return ""; }
|
||||||
try {
|
try {
|
||||||
|
@ -102,4 +96,22 @@ public class CommunityContentprovider {
|
||||||
if (selectioncriteria == null) { return ""; }
|
if (selectioncriteria == null) { return ""; }
|
||||||
return "<![CDATA[" + toJson() + "]]>";
|
return "<![CDATA[" + toJson() + "]]>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("CommunityContentprovider [\n\topenaireId = ")
|
||||||
|
.append(openaireId)
|
||||||
|
.append(",\n\tcommunityId = ")
|
||||||
|
.append(communityId)
|
||||||
|
.append(",\n\tname = ")
|
||||||
|
.append(name)
|
||||||
|
.append(",\n\tofficialname = ")
|
||||||
|
.append(officialname)
|
||||||
|
.append(",\n\tselectioncriteria = ")
|
||||||
|
.append(selectioncriteria)
|
||||||
|
.append("\n]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package eu.dnetlib.openaire.exporter.model.community;
|
package eu.dnetlib.openaire.exporter.model.community;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
@ -12,10 +12,10 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
public class CommunityDetails extends CommunitySummary {
|
public class CommunityDetails extends CommunitySummary {
|
||||||
|
|
||||||
@Schema(description = "date of creation for this community")
|
@Schema(description = "date of creation for this community")
|
||||||
private Date creationDate;
|
private LocalDateTime creationDate;
|
||||||
|
|
||||||
@Schema(description = "date of the last update for this communityu")
|
@Schema(description = "date of the last update for this communityu")
|
||||||
private Date lastUpdateDate;
|
private LocalDateTime lastUpdateDate;
|
||||||
|
|
||||||
@Schema(description = "list of subjects (keywords) that characterise this community")
|
@Schema(description = "list of subjects (keywords) that characterise this community")
|
||||||
private List<String> subjects;
|
private List<String> subjects;
|
||||||
|
@ -29,6 +29,15 @@ public class CommunityDetails extends CommunitySummary {
|
||||||
@Schema(description = "list of advanced criteria to associate results to this community")
|
@Schema(description = "list of advanced criteria to associate results to this community")
|
||||||
private SelectionCriteria advancedConstraints;
|
private SelectionCriteria advancedConstraints;
|
||||||
|
|
||||||
|
@Schema(description = "list of the remove criteria")
|
||||||
|
private SelectionCriteria removeConstraints;
|
||||||
|
|
||||||
|
@Schema(description = "other zenodo communities")
|
||||||
|
private List<String> otherZenodoCommunities;
|
||||||
|
|
||||||
|
@Schema(description = "Suggested Acknowledgements")
|
||||||
|
private List<String> suggestedAcknowledgements;
|
||||||
|
|
||||||
public CommunityDetails() {}
|
public CommunityDetails() {}
|
||||||
|
|
||||||
public CommunityDetails(final CommunitySummary summary) {
|
public CommunityDetails(final CommunitySummary summary) {
|
||||||
|
@ -36,12 +45,12 @@ public class CommunityDetails extends CommunitySummary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Date getCreationDate() {
|
public LocalDateTime getCreationDate() {
|
||||||
return creationDate;
|
return creationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCreationDate(final Date creationDate) {
|
public void setCreationDate(final LocalDateTime creationDate) {
|
||||||
this.creationDate = creationDate;
|
this.creationDate = creationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,12 +63,12 @@ public class CommunityDetails extends CommunitySummary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Date getLastUpdateDate() {
|
public LocalDateTime getLastUpdateDate() {
|
||||||
return lastUpdateDate;
|
return lastUpdateDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLastUpdateDate(final Date lastUpdateDate) {
|
public void setLastUpdateDate(final LocalDateTime lastUpdateDate) {
|
||||||
this.lastUpdateDate = lastUpdateDate;
|
this.lastUpdateDate = lastUpdateDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,4 +95,74 @@ public class CommunityDetails extends CommunitySummary {
|
||||||
public void setAdvancedConstraints(final SelectionCriteria advancedConstraints) {
|
public void setAdvancedConstraints(final SelectionCriteria advancedConstraints) {
|
||||||
this.advancedConstraints = advancedConstraints;
|
this.advancedConstraints = advancedConstraints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SelectionCriteria getRemoveConstraints() {
|
||||||
|
return removeConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemoveConstraints(final SelectionCriteria removeConstraints) {
|
||||||
|
this.removeConstraints = removeConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getOtherZenodoCommunities() {
|
||||||
|
return otherZenodoCommunities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOtherZenodoCommunities(final List<String> otherZenodoCommunities) {
|
||||||
|
this.otherZenodoCommunities = otherZenodoCommunities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getSuggestedAcknowledgements() {
|
||||||
|
return suggestedAcknowledgements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSuggestedAcknowledgements(final List<String> suggestedAcknowledgements) {
|
||||||
|
this.suggestedAcknowledgements = suggestedAcknowledgements;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("CommunityDetails [\n\tcreationDate = ")
|
||||||
|
.append(creationDate)
|
||||||
|
.append(",\n\tlastUpdateDate = ")
|
||||||
|
.append(lastUpdateDate)
|
||||||
|
.append(",\n\tsubjects = ")
|
||||||
|
.append(subjects)
|
||||||
|
.append(",\n\tfos = ")
|
||||||
|
.append(fos)
|
||||||
|
.append(",\n\tsdg = ")
|
||||||
|
.append(sdg)
|
||||||
|
.append(",\n\tadvancedConstraints = ")
|
||||||
|
.append(advancedConstraints)
|
||||||
|
.append(",\n\tremoveConstraints = ")
|
||||||
|
.append(removeConstraints)
|
||||||
|
.append(",\n\totherZenodoCommunities = ")
|
||||||
|
.append(otherZenodoCommunities)
|
||||||
|
.append(",\n\tid = ")
|
||||||
|
.append(id)
|
||||||
|
.append(",\n\tqueryId = ")
|
||||||
|
.append(queryId)
|
||||||
|
.append(",\n\ttype = ")
|
||||||
|
.append(type)
|
||||||
|
.append(",\n\tname = ")
|
||||||
|
.append(name)
|
||||||
|
.append(",\n\tshortName = ")
|
||||||
|
.append(shortName)
|
||||||
|
.append(",\n\tdescription = ")
|
||||||
|
.append(description)
|
||||||
|
.append(",\n\tlogoUrl = ")
|
||||||
|
.append(logoUrl)
|
||||||
|
.append(",\n\tstatus = ")
|
||||||
|
.append(status)
|
||||||
|
.append(",\n\tzenodoCommunity = ")
|
||||||
|
.append(zenodoCommunity)
|
||||||
|
.append(",\n\tsuggestedAcknowledgements = ")
|
||||||
|
.append(suggestedAcknowledgements)
|
||||||
|
.append(",\n\tplan = ")
|
||||||
|
.append(plan)
|
||||||
|
.append("\n]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package eu.dnetlib.openaire.exporter.model.community;
|
||||||
|
|
||||||
|
public enum CommunityMembershipType {
|
||||||
|
|
||||||
|
open("open"),
|
||||||
|
byInvitation("by-invitation");
|
||||||
|
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
private CommunityMembershipType(final String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommunityMembershipType fromDescription(final String dbData) {
|
||||||
|
for (final CommunityMembershipType t : CommunityMembershipType.values()) {
|
||||||
|
if (t.description.equalsIgnoreCase(dbData)) { return t; }
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,10 +17,6 @@ public class CommunityOrganization {
|
||||||
@Schema(description = "name of the organization", required = true)
|
@Schema(description = "name of the organization", required = true)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Schema(description = "identifies this organization within the context it belongs to", required = true)
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Schema(description = "url of the logo for this organization", required = true)
|
@Schema(description = "url of the logo for this organization", required = true)
|
||||||
private String logo_url;
|
private String logo_url;
|
||||||
|
@ -47,15 +43,6 @@ public class CommunityOrganization {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommunityOrganization setId(final String id) {
|
|
||||||
this.id = id;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLogo_url() {
|
public String getLogo_url() {
|
||||||
return logo_url;
|
return logo_url;
|
||||||
}
|
}
|
||||||
|
@ -73,4 +60,19 @@ public class CommunityOrganization {
|
||||||
this.website_url = website_url;
|
this.website_url = website_url;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("CommunityOrganization [\n\tcommunityId = ")
|
||||||
|
.append(communityId)
|
||||||
|
.append(",\n\tname = ")
|
||||||
|
.append(name)
|
||||||
|
.append(",\n\tlogo_url = ")
|
||||||
|
.append(logo_url)
|
||||||
|
.append(",\n\twebsite_url = ")
|
||||||
|
.append(website_url)
|
||||||
|
.append("\n]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package eu.dnetlib.openaire.exporter.model.community;
|
package eu.dnetlib.openaire.exporter.model.community;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
@ -13,9 +15,6 @@ public class CommunityProject {
|
||||||
@Schema(description = "the community identifier this project belongs to", required = true)
|
@Schema(description = "the community identifier this project belongs to", required = true)
|
||||||
private String communityId;
|
private String communityId;
|
||||||
|
|
||||||
@Schema(description = "identifies this project within the context it belongs to", required = true)
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
@Schema(description = "project name", required = true)
|
@Schema(description = "project name", required = true)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ -28,6 +27,9 @@ public class CommunityProject {
|
||||||
@Schema(description = "project grant id", required = true)
|
@Schema(description = "project grant id", required = true)
|
||||||
private String grantId;
|
private String grantId;
|
||||||
|
|
||||||
|
@Schema(description = "available since", required = false)
|
||||||
|
private LocalDate availableSince;
|
||||||
|
|
||||||
public String getOpenaireId() {
|
public String getOpenaireId() {
|
||||||
return openaireId;
|
return openaireId;
|
||||||
}
|
}
|
||||||
|
@ -44,14 +46,6 @@ public class CommunityProject {
|
||||||
this.communityId = communityId;
|
this.communityId = communityId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(final String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -84,4 +78,33 @@ public class CommunityProject {
|
||||||
this.grantId = grantId;
|
this.grantId = grantId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LocalDate getAvailableSince() {
|
||||||
|
return availableSince;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAvailableSince(final LocalDate availableSince) {
|
||||||
|
this.availableSince = availableSince;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("CommunityProject [\n\topenaireId = ")
|
||||||
|
.append(openaireId)
|
||||||
|
.append(",\n\tcommunityId = ")
|
||||||
|
.append(communityId)
|
||||||
|
.append(",\n\tname = ")
|
||||||
|
.append(name)
|
||||||
|
.append(",\n\tacronym = ")
|
||||||
|
.append(acronym)
|
||||||
|
.append(",\n\tfunder = ")
|
||||||
|
.append(funder)
|
||||||
|
.append(",\n\tgrantId = ")
|
||||||
|
.append(funder)
|
||||||
|
.append(",\n\tavailableSince = ")
|
||||||
|
.append(availableSince)
|
||||||
|
.append("\n]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,19 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
@JsonAutoDetect
|
@JsonAutoDetect
|
||||||
public enum CommunityStatus {
|
public enum CommunityStatus {
|
||||||
|
|
||||||
@Schema(description = "restricted visibility")
|
@Schema(description = "hidden visibility")
|
||||||
hidden,
|
hidden,
|
||||||
|
|
||||||
@Schema(description = "visible only to RCD managers")
|
@Schema(description = "visible only to RCD managers")
|
||||||
manager,
|
manager,
|
||||||
|
|
||||||
@Schema(description = "visible to RCD managers and to the community users")
|
@Schema(description = "visible to RCD managers and to the community users")
|
||||||
all
|
all,
|
||||||
|
|
||||||
|
@Schema(description = "restricted visibility")
|
||||||
|
RESTRICTED,
|
||||||
|
|
||||||
|
@Schema(description = "public visibility")
|
||||||
|
PUBLIC
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package eu.dnetlib.openaire.exporter.model.community;
|
package eu.dnetlib.openaire.exporter.model.community;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ public class CommunitySummary {
|
||||||
protected String queryId;
|
protected String queryId;
|
||||||
|
|
||||||
@Schema(description = "community type")
|
@Schema(description = "community type")
|
||||||
protected String type;
|
protected CommunityType type;
|
||||||
|
|
||||||
@Schema(description = "community name")
|
@Schema(description = "community name")
|
||||||
protected String name;
|
protected String name;
|
||||||
|
@ -25,10 +25,10 @@ public class CommunitySummary {
|
||||||
protected String shortName;
|
protected String shortName;
|
||||||
|
|
||||||
@Schema(description = "community creation date")
|
@Schema(description = "community creation date")
|
||||||
protected Date creationDate;
|
protected LocalDateTime creationDate;
|
||||||
|
|
||||||
@Schema(description = "community last update date")
|
@Schema(description = "community last update date")
|
||||||
protected Date lastUpdateDate;
|
protected LocalDateTime lastUpdateDate;
|
||||||
|
|
||||||
@Schema(description = "community description")
|
@Schema(description = "community description")
|
||||||
protected String description;
|
protected String description;
|
||||||
|
@ -39,23 +39,33 @@ public class CommunitySummary {
|
||||||
@Schema(description = "status of the community, drives its visibility")
|
@Schema(description = "status of the community, drives its visibility")
|
||||||
protected CommunityStatus status;
|
protected CommunityStatus status;
|
||||||
|
|
||||||
|
@Schema(description = "type of claim")
|
||||||
|
private CommunityClaimType claim;
|
||||||
|
|
||||||
|
@Schema(description = "type of membership")
|
||||||
|
private CommunityMembershipType membership;
|
||||||
|
|
||||||
@Schema(description = "Zenodo community associated to this community")
|
@Schema(description = "Zenodo community associated to this community")
|
||||||
protected String zenodoCommunity;
|
protected String zenodoCommunity;
|
||||||
|
|
||||||
|
@Schema(description = "community plan")
|
||||||
|
protected String plan;
|
||||||
|
|
||||||
public CommunitySummary() {}
|
public CommunitySummary() {}
|
||||||
|
|
||||||
public CommunitySummary(
|
public CommunitySummary(
|
||||||
final String id,
|
final String id,
|
||||||
final String queryId,
|
final String queryId,
|
||||||
final String type,
|
final CommunityType type,
|
||||||
final String name,
|
final String name,
|
||||||
final String shortName,
|
final String shortName,
|
||||||
final Date creationDate,
|
final LocalDateTime creationDate,
|
||||||
final Date lastUpdateDate,
|
final LocalDateTime lastUpdateDate,
|
||||||
final String description,
|
final String description,
|
||||||
final String logoUrl,
|
final String logoUrl,
|
||||||
final CommunityStatus status,
|
final CommunityStatus status,
|
||||||
final String zenodoCommunity) {
|
final String zenodoCommunity,
|
||||||
|
final String plan) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.queryId = queryId;
|
this.queryId = queryId;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
@ -67,6 +77,7 @@ public class CommunitySummary {
|
||||||
this.logoUrl = logoUrl;
|
this.logoUrl = logoUrl;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.zenodoCommunity = zenodoCommunity;
|
this.zenodoCommunity = zenodoCommunity;
|
||||||
|
this.plan = plan;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunitySummary(final CommunitySummary summary) {
|
public CommunitySummary(final CommunitySummary summary) {
|
||||||
|
@ -80,7 +91,8 @@ public class CommunitySummary {
|
||||||
summary.getDescription(),
|
summary.getDescription(),
|
||||||
summary.getLogoUrl(),
|
summary.getLogoUrl(),
|
||||||
summary.getStatus(),
|
summary.getStatus(),
|
||||||
summary.getZenodoCommunity());
|
summary.getZenodoCommunity(),
|
||||||
|
summary.getPlan());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
@ -99,11 +111,11 @@ public class CommunitySummary {
|
||||||
this.queryId = queryId;
|
this.queryId = queryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getType() {
|
public CommunityType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(final String type) {
|
public void setType(final CommunityType type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,19 +135,19 @@ public class CommunitySummary {
|
||||||
this.shortName = shortName;
|
this.shortName = shortName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCreationDate() {
|
public LocalDateTime getCreationDate() {
|
||||||
return creationDate;
|
return creationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreationDate(final Date creationDate) {
|
public void setCreationDate(final LocalDateTime creationDate) {
|
||||||
this.creationDate = creationDate;
|
this.creationDate = creationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getLastUpdateDate() {
|
public LocalDateTime getLastUpdateDate() {
|
||||||
return lastUpdateDate;
|
return lastUpdateDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastUpdateDate(final Date lastUpdateDate) {
|
public void setLastUpdateDate(final LocalDateTime lastUpdateDate) {
|
||||||
this.lastUpdateDate = lastUpdateDate;
|
this.lastUpdateDate = lastUpdateDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,6 +175,22 @@ public class CommunitySummary {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommunityClaimType getClaim() {
|
||||||
|
return claim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClaim(final CommunityClaimType claim) {
|
||||||
|
this.claim = claim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommunityMembershipType getMembership() {
|
||||||
|
return membership;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMembership(final CommunityMembershipType membership) {
|
||||||
|
this.membership = membership;
|
||||||
|
}
|
||||||
|
|
||||||
public String getZenodoCommunity() {
|
public String getZenodoCommunity() {
|
||||||
return zenodoCommunity;
|
return zenodoCommunity;
|
||||||
}
|
}
|
||||||
|
@ -171,4 +199,12 @@ public class CommunitySummary {
|
||||||
this.zenodoCommunity = zenodoCommunity;
|
this.zenodoCommunity = zenodoCommunity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPlan() {
|
||||||
|
return plan;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlan(final String plan) {
|
||||||
|
this.plan = plan;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package eu.dnetlib.openaire.exporter.model.community;
|
||||||
|
|
||||||
|
public enum CommunityType {
|
||||||
|
community,
|
||||||
|
ri
|
||||||
|
}
|
|
@ -34,26 +34,29 @@ public class CommunityWritableProperties {
|
||||||
@Schema(description = "Advanced constraint for the association of results to the community")
|
@Schema(description = "Advanced constraint for the association of results to the community")
|
||||||
private SelectionCriteria advancedConstraints;
|
private SelectionCriteria advancedConstraints;
|
||||||
|
|
||||||
|
@Schema(description = "Constraint for removing")
|
||||||
|
private SelectionCriteria removeConstraints;
|
||||||
|
|
||||||
@Schema(description = "status of the community, drives its visibility")
|
@Schema(description = "status of the community, drives its visibility")
|
||||||
private CommunityStatus status;
|
private CommunityStatus status;
|
||||||
|
|
||||||
@Schema(description = "id of the main Zenodo community")
|
@Schema(description = "id of the main Zenodo community")
|
||||||
private String mainZenodoCommunity;
|
private String mainZenodoCommunity;
|
||||||
|
|
||||||
public static CommunityWritableProperties fromDetails(final CommunityDetails details) {
|
@Schema(description = "identifiers of the other Zenodo community")
|
||||||
final CommunityWritableProperties p = new CommunityWritableProperties();
|
private List<String> otherZenodoCommunities;
|
||||||
p.setName(details.getName());
|
|
||||||
p.setShortName(details.getShortName());
|
@Schema(description = "membership of the community")
|
||||||
p.setDescription(details.getDescription());
|
private CommunityMembershipType membership;
|
||||||
p.setLogoUrl(details.getLogoUrl());
|
|
||||||
p.setSubjects(details.getSubjects());
|
@Schema(description = "type of the community")
|
||||||
p.setStatus(details.getStatus());
|
private CommunityType type;
|
||||||
p.setMainZenodoCommunity(details.getZenodoCommunity());
|
|
||||||
p.setFos(details.getFos());
|
@Schema(description = "type of supported claim")
|
||||||
p.setSdg(details.getSdg());
|
private CommunityClaimType claim;
|
||||||
p.setAdvancedConstraints(details.getAdvancedConstraints());
|
|
||||||
return p;
|
@Schema(description = "community plan")
|
||||||
}
|
private String plan;
|
||||||
|
|
||||||
public List<String> getFos() {
|
public List<String> getFos() {
|
||||||
return fos;
|
return fos;
|
||||||
|
@ -134,4 +137,52 @@ public class CommunityWritableProperties {
|
||||||
public void setMainZenodoCommunity(final String mainZenodoCommunity) {
|
public void setMainZenodoCommunity(final String mainZenodoCommunity) {
|
||||||
this.mainZenodoCommunity = mainZenodoCommunity;
|
this.mainZenodoCommunity = mainZenodoCommunity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommunityMembershipType getMembership() {
|
||||||
|
return membership;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMembership(final CommunityMembershipType membership) {
|
||||||
|
this.membership = membership;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommunityType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(final CommunityType type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommunityClaimType getClaim() {
|
||||||
|
return claim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClaim(final CommunityClaimType claim) {
|
||||||
|
this.claim = claim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SelectionCriteria getRemoveConstraints() {
|
||||||
|
return removeConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemoveConstraints(final SelectionCriteria removeConstraints) {
|
||||||
|
this.removeConstraints = removeConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getOtherZenodoCommunities() {
|
||||||
|
return otherZenodoCommunities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOtherZenodoCommunities(final List<String> otherZenodoCommunities) {
|
||||||
|
this.otherZenodoCommunities = otherZenodoCommunities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlan() {
|
||||||
|
return plan;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlan(final String plan) {
|
||||||
|
this.plan = plan;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
@JsonAutoDetect
|
@JsonAutoDetect
|
||||||
|
@Deprecated
|
||||||
public class CommunityZenodoCommunity {
|
public class CommunityZenodoCommunity {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|
|
@ -0,0 +1,125 @@
|
||||||
|
package eu.dnetlib.openaire.exporter.model.community;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
|
||||||
|
import eu.dnetlib.openaire.exporter.model.context.Param;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
|
@JsonAutoDetect
|
||||||
|
public class SubCommunity {
|
||||||
|
|
||||||
|
@Schema(description = "the id of the subCommunity", required = true)
|
||||||
|
private String subCommunityId;
|
||||||
|
|
||||||
|
@Schema(description = "the community identifier this sub community belongs to", required = true)
|
||||||
|
private String communityId;
|
||||||
|
|
||||||
|
@Schema(description = "the parent of the subCommunity, if available (it should the id of another subCommunity)", required = false)
|
||||||
|
private String parent;
|
||||||
|
|
||||||
|
@Schema(description = "the label of the subCommunity", required = true)
|
||||||
|
private String label;
|
||||||
|
|
||||||
|
@Schema(description = "the category of the subCommunity", required = true)
|
||||||
|
private String category;
|
||||||
|
|
||||||
|
@Schema(description = "the parameters of the subCommunity", required = true)
|
||||||
|
private List<Param> params = new ArrayList<>();
|
||||||
|
|
||||||
|
@Schema(description = "it supports the claims", required = true)
|
||||||
|
private boolean claim = false;
|
||||||
|
|
||||||
|
@Schema(description = "it is browsable", required = true)
|
||||||
|
private boolean browsable = false;
|
||||||
|
|
||||||
|
public String getSubCommunityId() {
|
||||||
|
return subCommunityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubCommunityId(final String subCommunityId) {
|
||||||
|
this.subCommunityId = subCommunityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommunityId() {
|
||||||
|
return communityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCommunityId(final String communityId) {
|
||||||
|
this.communityId = communityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParent(final String parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(final String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategory(final String category) {
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Param> getParams() {
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParams(final List<Param> map) {
|
||||||
|
this.params = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isClaim() {
|
||||||
|
return claim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClaim(final boolean claim) {
|
||||||
|
this.claim = claim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBrowsable() {
|
||||||
|
return browsable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBrowsable(final boolean browsable) {
|
||||||
|
this.browsable = browsable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("SubCommunity [\n\tsubCommunityId = ")
|
||||||
|
.append(subCommunityId)
|
||||||
|
.append(",\n\tcommunityId = ")
|
||||||
|
.append(communityId)
|
||||||
|
.append(",\n\tparent = ")
|
||||||
|
.append(parent)
|
||||||
|
.append(",\n\tlabel = ")
|
||||||
|
.append(label)
|
||||||
|
.append(",\n\tcategory = ")
|
||||||
|
.append(category)
|
||||||
|
.append(",\n\tparams = ")
|
||||||
|
.append(params)
|
||||||
|
.append(",\n\tclaim = ")
|
||||||
|
.append(claim)
|
||||||
|
.append(",\n\tbrowsable = ")
|
||||||
|
.append(browsable)
|
||||||
|
.append("\n]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3,14 +3,14 @@ package eu.dnetlib.openaire.exporter.model.community.selectioncriteria;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
@JsonAutoDetect
|
@JsonAutoDetect
|
||||||
public class SelectionCriteria implements Serializable {
|
public class SelectionCriteria implements Serializable {
|
||||||
|
|
||||||
|
@ -32,9 +32,7 @@ public class SelectionCriteria implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SelectionCriteria fromJson(final String json) {
|
public static SelectionCriteria fromJson(final String json) {
|
||||||
if(StringUtils.isEmpty(json)){
|
if (StringUtils.isEmpty(json)) { return null; }
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
return new ObjectMapper().readValue(json, SelectionCriteria.class);
|
return new ObjectMapper().readValue(json, SelectionCriteria.class);
|
||||||
} catch (final JsonProcessingException e) {
|
} catch (final JsonProcessingException e) {
|
||||||
|
@ -43,4 +41,12 @@ public class SelectionCriteria implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toJson() {
|
||||||
|
try {
|
||||||
|
return new ObjectMapper().writeValueAsString(this);
|
||||||
|
} catch (final JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package eu.dnetlib.openaire.exporter.model.context;
|
package eu.dnetlib.openaire.exporter.model.context;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class Category {
|
public class Category {
|
||||||
|
|
||||||
|
@ -11,7 +10,7 @@ public class Category {
|
||||||
|
|
||||||
private boolean claim;
|
private boolean claim;
|
||||||
|
|
||||||
private Map<String, List<Param>> params;
|
private List<Param> params;
|
||||||
|
|
||||||
private List<Concept> concepts;
|
private List<Concept> concepts;
|
||||||
|
|
||||||
|
@ -31,7 +30,7 @@ public class Category {
|
||||||
return getConcepts() != null && !getConcepts().isEmpty();
|
return getConcepts() != null && !getConcepts().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, List<Param>> getParams() {
|
public List<Param> getParams() {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +53,7 @@ public class Category {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Category setParams(final Map<String, List<Param>> params) {
|
public Category setParams(final List<Param> params) {
|
||||||
this.params = params;
|
this.params = params;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package eu.dnetlib.openaire.exporter.model.context;
|
package eu.dnetlib.openaire.exporter.model.context;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class CategorySummary {
|
public class CategorySummary {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
@ -35,4 +37,17 @@ public class CategorySummary {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object obj) {
|
||||||
|
if (this == obj) { return true; }
|
||||||
|
if (!(obj instanceof CategorySummary)) { return false; }
|
||||||
|
final CategorySummary other = (CategorySummary) obj;
|
||||||
|
return Objects.equals(id, other.id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package eu.dnetlib.openaire.exporter.model.context;
|
package eu.dnetlib.openaire.exporter.model.context;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class Concept {
|
public class Concept {
|
||||||
|
|
||||||
|
@ -11,7 +10,7 @@ public class Concept {
|
||||||
|
|
||||||
private boolean claim;
|
private boolean claim;
|
||||||
|
|
||||||
private Map<String, List<Param>> params;
|
private List<Param> params;
|
||||||
|
|
||||||
private List<Concept> concepts;
|
private List<Concept> concepts;
|
||||||
|
|
||||||
|
@ -31,7 +30,7 @@ public class Concept {
|
||||||
return claim;
|
return claim;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, List<Param>> getParams() {
|
public List<Param> getParams() {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +53,7 @@ public class Concept {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Concept setParams(final Map<String, List<Param>> params) {
|
public Concept setParams(final List<Param> params) {
|
||||||
this.params = params;
|
this.params = params;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class Context {
|
||||||
|
|
||||||
private Date lastUpdateDate;
|
private Date lastUpdateDate;
|
||||||
|
|
||||||
private Map<String, List<Param>> params;
|
private List<Param> params;
|
||||||
|
|
||||||
private Map<String, Category> categories;
|
private Map<String, Category> categories;
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public class Context {
|
||||||
return creationDate;
|
return creationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, List<Param>> getParams() {
|
public List<Param> getParams() {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ public class Context {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Context setParams(final Map<String, List<Param>> params) {
|
public Context setParams(final List<Param> params) {
|
||||||
this.params = params;
|
this.params = params;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package eu.dnetlib.openaire.exporter.model.context;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
public class IISConfigurationEntry implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -1470248262314248937L;
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private String label;
|
||||||
|
private List<Param> params = new ArrayList<>();
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(final String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(final String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Param> getParams() {
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParams(final List<Param> params) {
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addParams(final String name, final String... values) {
|
||||||
|
if (StringUtils.isNoneBlank(name) && values != null) {
|
||||||
|
for (final String v : values) {
|
||||||
|
if (StringUtils.isNotBlank(v)) {
|
||||||
|
params.add(new Param().setName(name).setValue(v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,10 @@
|
||||||
package eu.dnetlib.openaire.exporter.model.context;
|
package eu.dnetlib.openaire.exporter.model.context;
|
||||||
|
|
||||||
public class Param {
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class Param implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -1534376651378828800L;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue