bug fix
This commit is contained in:
parent
653e925cff
commit
7d91da1099
|
@ -6,6 +6,8 @@ import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
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;
|
||||||
|
@ -16,7 +18,6 @@ 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.CommunityException;
|
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.CommunityType;
|
||||||
import eu.dnetlib.openaire.exporter.model.community.SubCommunity;
|
import eu.dnetlib.openaire.exporter.model.community.SubCommunity;
|
||||||
import eu.dnetlib.openaire.exporter.model.context.CategorySummary;
|
import eu.dnetlib.openaire.exporter.model.context.CategorySummary;
|
||||||
|
@ -38,6 +39,8 @@ public class ContextApiController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private CommunityService communityService;
|
private CommunityService communityService;
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(ContextApiController.class);
|
||||||
|
|
||||||
@RequestMapping(value = "/contexts", produces = {
|
@RequestMapping(value = "/contexts", produces = {
|
||||||
"application/json"
|
"application/json"
|
||||||
}, method = RequestMethod.GET)
|
}, method = RequestMethod.GET)
|
||||||
|
@ -71,14 +74,15 @@ public class ContextApiController {
|
||||||
})
|
})
|
||||||
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 ResourceNotFoundException, CommunityException {
|
@RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException {
|
||||||
|
|
||||||
|
try {
|
||||||
return communityService.getSubCommunities(contextId)
|
return communityService.getSubCommunities(contextId)
|
||||||
.stream()
|
.stream()
|
||||||
.filter(sc -> all || sc.isClaim())
|
.filter(sc -> all || sc.isClaim())
|
||||||
.map(sc -> {
|
.map(sc -> {
|
||||||
final String[] parts = StringUtils.split(sc.getSubCommunityId());
|
final String[] parts = StringUtils.split(sc.getSubCommunityId(), "::");
|
||||||
if (parts.length < 3) { throw new RuntimeException("Invalid conceptId (It should have 3 (or more) parts)"); }
|
if (parts.length < 3) { throw new RuntimeException("Invalid conceptId (It should have 3 (or more) parts): " + sc.getSubCommunityId()); }
|
||||||
final CategorySummary cat = new CategorySummary();
|
final CategorySummary cat = new CategorySummary();
|
||||||
cat.setId(parts[0] + "::" + parts[1]);
|
cat.setId(parts[0] + "::" + parts[1]);
|
||||||
cat.setLabel(sc.getLabel());
|
cat.setLabel(sc.getLabel());
|
||||||
|
@ -87,6 +91,10 @@ public class ContextApiController {
|
||||||
})
|
})
|
||||||
.distinct()
|
.distinct()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
throw new CommunityException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/context/category/{categoryId}", produces = {
|
@RequestMapping(value = "/context/category/{categoryId}", produces = {
|
||||||
|
@ -101,8 +109,11 @@ public class ContextApiController {
|
||||||
@PathVariable final String categoryId,
|
@PathVariable final String categoryId,
|
||||||
@RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException {
|
@RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException {
|
||||||
|
|
||||||
final String[] parts = StringUtils.split(categoryId);
|
final String[] parts = StringUtils.split(categoryId, "::");
|
||||||
if (parts.length != 2) { throw new CommunityException("Invalid category id (it should have 2 parts"); }
|
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 String contextId = parts[0];
|
||||||
|
|
||||||
|
@ -122,16 +133,19 @@ public class ContextApiController {
|
||||||
})
|
})
|
||||||
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 ResourceNotFoundException, CommunityException {
|
@RequestParam(required = false, defaultValue = "false") final boolean all) throws CommunityException {
|
||||||
|
|
||||||
final String[] parts = StringUtils.split(conceptId);
|
final String[] parts = StringUtils.split(conceptId, "::");
|
||||||
if (parts.length < 3) { throw new CommunityException("Invalid concept id (it should have 3 (or more) parts"); }
|
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 String contextId = parts[0];
|
final String contextId = parts[0];
|
||||||
|
|
||||||
final List<SubCommunity> list = findSubCommunities(conceptId + "::", all, contextId);
|
final List<SubCommunity> list = findSubCommunities(conceptId + "::", all, contextId);
|
||||||
|
|
||||||
return processSubCommunities(contextId, list);
|
return processSubCommunities(conceptId, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SubCommunity> findSubCommunities(final String prefix, final boolean all, final String contextId) throws CommunityException {
|
private List<SubCommunity> findSubCommunities(final String prefix, final boolean all, final String contextId) throws CommunityException {
|
||||||
|
|
Loading…
Reference in New Issue