new_model_for_communities #15
|
@ -23,7 +23,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import eu.dnetlib.openaire.community.CommunityService;
|
||||
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
|
||||
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
|
||||
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
|
||||
|
|
|
@ -42,15 +42,13 @@ 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.ConceptSummary;
|
||||
|
||||
@Service
|
||||
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
||||
public class CommunityService {
|
||||
|
||||
// TODO
|
||||
// 1) Subcommunities: visualizzazione tramite le context api
|
||||
// 2) Test di import (context e wf)
|
||||
// 3) Verificare Tickets: #8835, #8854, #6483, #3259, #3494
|
||||
// TODO: Verificare Tickets: #8835, #8854, #6483, #3259, #3494
|
||||
|
||||
@Autowired
|
||||
private DbCommunityRepository dbCommunityRepository;
|
||||
|
@ -347,4 +345,9 @@ public class CommunityService {
|
|||
return getPropagationOrganizationsForCommunity(communityId);
|
||||
}
|
||||
|
||||
public List<ConceptSummary> listSubConcepts(final String conceptId, final boolean all) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,160 @@
|
|||
package eu.dnetlib.openaire.community;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import eu.dnetlib.openaire.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.ConceptSummary;
|
||||
import eu.dnetlib.openaire.exporter.model.context.ContextSummary;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(origins = {
|
||||
"*"
|
||||
})
|
||||
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
||||
@Tag(name = "OpenAIRE Context API", description = "the OpenAIRE Context API")
|
||||
public class ContextApiController {
|
||||
|
||||
@Autowired
|
||||
private CommunityService communityService;
|
||||
|
||||
@RequestMapping(value = "/contexts", produces = {
|
||||
"application/json"
|
||||
}, method = RequestMethod.GET)
|
||||
@Operation(summary = "list brief information about all the context profiles", description = "list brief information about all the context profiles")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||
})
|
||||
public List<ContextSummary> listContexts(@RequestParam(required = false) final Set<CommunityType> type) throws CommunityException {
|
||||
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());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/context/{contextId}", produces = {
|
||||
"application/json"
|
||||
}, method = RequestMethod.GET)
|
||||
@Operation(summary = "list the categories defined within a context", description = "list the categories defined within a context")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||
})
|
||||
public List<CategorySummary> listCategories(
|
||||
@PathVariable final String contextId,
|
||||
@RequestParam(required = false, defaultValue = "false") final boolean all) throws ResourceNotFoundException, CommunityException {
|
||||
|
||||
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)"); }
|
||||
final CategorySummary cat = new CategorySummary();
|
||||
cat.setId(parts[0] + "::" + parts[1]);
|
||||
cat.setLabel(sc.getLabel());
|
||||
cat.setHasConcept(true);
|
||||
return cat;
|
||||
})
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/context/category/{categoryId}", produces = {
|
||||
"application/json"
|
||||
}, method = RequestMethod.GET)
|
||||
@Operation(summary = "list the concepts defined within a category", description = "list the concepts defined within a category")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||
})
|
||||
public List<ConceptSummary> listConcepts(
|
||||
@PathVariable final String categoryId,
|
||||
@RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException {
|
||||
|
||||
final String[] parts = StringUtils.split(categoryId);
|
||||
if (parts.length != 2) { throw new CommunityException("Invalid category id (it should have 2 parts"); }
|
||||
|
||||
final String contextId = parts[0];
|
||||
|
||||
final List<SubCommunity> list = findSubCommunities(categoryId + "::", all, contextId);
|
||||
|
||||
return processSubCommunities(null, list);
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/context/category/concept/{conceptId}", produces = {
|
||||
"application/json"
|
||||
}, method = RequestMethod.GET)
|
||||
@Operation(summary = "list the concepts defined within a category", description = "list the concepts defined within a category")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "500", description = "unexpected error")
|
||||
})
|
||||
public List<ConceptSummary> listSubConcepts(
|
||||
@PathVariable final String conceptId,
|
||||
@RequestParam(required = false, defaultValue = "false") final boolean all) throws ResourceNotFoundException, CommunityException {
|
||||
|
||||
final String[] parts = StringUtils.split(conceptId);
|
||||
if (parts.length < 3) { throw new CommunityException("Invalid concept id (it should have 3 (or more) parts"); }
|
||||
|
||||
final String contextId = parts[0];
|
||||
|
||||
final List<SubCommunity> list = findSubCommunities(conceptId + "::", all, contextId);
|
||||
|
||||
return processSubCommunities(contextId, list);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
|
@ -4,13 +4,10 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import eu.dnetlib.openaire.exporter.exceptions.ContextException;
|
||||
import eu.dnetlib.openaire.exporter.model.context.CategorySummary;
|
||||
|
@ -19,14 +16,13 @@ import eu.dnetlib.openaire.exporter.model.context.ContextSummary;
|
|||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(origins = {
|
||||
"*"
|
||||
})
|
||||
@ConditionalOnProperty(value = "openaire.exporter.enable.context", havingValue = "true")
|
||||
@Tag(name = "OpenAIRE Context API", description = "the OpenAIRE Context API")
|
||||
// @RestController
|
||||
// @CrossOrigin(origins = { "*" })
|
||||
// @ConditionalOnProperty(value = "openaire.exporter.enable.context", havingValue = "true")
|
||||
// @Tag(name = "OpenAIRE Context API", description = "the OpenAIRE Context API")
|
||||
@Deprecated
|
||||
// THIS APIs HAS BEEN REIMPLEMENTED UNDER THE COMMUNITY APIs
|
||||
public class ContextApiController {
|
||||
|
||||
@Autowired
|
||||
|
|
|
@ -8,8 +8,6 @@ import java.util.stream.Stream;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
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.collect.Lists;
|
||||
|
@ -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.ContextSummary;
|
||||
|
||||
@Component
|
||||
@ConditionalOnProperty(value = "openaire.exporter.enable.context", havingValue = "true")
|
||||
// @Component
|
||||
// @ConditionalOnProperty(value = "openaire.exporter.enable.context", havingValue = "true")
|
||||
@Deprecated
|
||||
public class ContextApiCore {
|
||||
|
||||
private static final String SEPARATOR = "::";
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package eu.dnetlib.openaire.exporter.model.context;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class CategorySummary {
|
||||
|
||||
private String id;
|
||||
|
@ -35,4 +37,17 @@ public class CategorySummary {
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue