context apis

This commit is contained in:
Michele Artini 2022-06-24 15:44:53 +02:00
parent a36745ab8b
commit 0855c17f4a
7 changed files with 27 additions and 12 deletions

View File

@ -18,8 +18,8 @@ import eu.dnetlib.is.context.model.ConceptLevel0;
import eu.dnetlib.is.context.model.ConceptLevel1; import eu.dnetlib.is.context.model.ConceptLevel1;
import eu.dnetlib.is.context.model.ConceptLevel2; import eu.dnetlib.is.context.model.ConceptLevel2;
import eu.dnetlib.is.context.model.Context; import eu.dnetlib.is.context.model.Context;
import eu.dnetlib.is.context.model.CtxChildInfo;
import eu.dnetlib.is.context.model.CtxInfo; import eu.dnetlib.is.context.model.CtxInfo;
import eu.dnetlib.is.context.model.CtxInfoWithClaim;
import eu.dnetlib.is.context.model.Parameter; import eu.dnetlib.is.context.model.Parameter;
import eu.dnetlib.is.context.model.repository.CategoryRepository; import eu.dnetlib.is.context.model.repository.CategoryRepository;
import eu.dnetlib.is.context.model.repository.ConceptLevel0Repository; import eu.dnetlib.is.context.model.repository.ConceptLevel0Repository;
@ -101,9 +101,9 @@ public class ContextImporter {
private void setCommonInfo(final CtxInfo o, final String parent, final Node n) { private void setCommonInfo(final CtxInfo o, final String parent, final Node n) {
o.setId(n.valueOf("@id")); o.setId(n.valueOf("@id"));
o.setLabel(n.valueOf("@label")); o.setLabel(n.valueOf("@label"));
if (o instanceof CtxInfoWithClaim) { if (o instanceof CtxChildInfo) {
((CtxInfoWithClaim) o).setParent(parent); ((CtxChildInfo) o).setParent(parent);
((CtxInfoWithClaim) o).setClaim(BooleanUtils.toBoolean(n.valueOf("@claim"))); ((CtxChildInfo) o).setClaim(BooleanUtils.toBoolean(n.valueOf("@claim")));
} }
o.setParameters(n.selectNodes("./param") o.setParameters(n.selectNodes("./param")
.stream() .stream()

View File

@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController;
import eu.dnetlib.is.context.model.Category; import eu.dnetlib.is.context.model.Category;
import eu.dnetlib.is.context.model.Context; import eu.dnetlib.is.context.model.Context;
import eu.dnetlib.is.context.model.CtxChildInfo;
import eu.dnetlib.is.context.model.repository.CategoryRepository; import eu.dnetlib.is.context.model.repository.CategoryRepository;
import eu.dnetlib.is.context.model.repository.ConceptLevel0Repository; import eu.dnetlib.is.context.model.repository.ConceptLevel0Repository;
import eu.dnetlib.is.context.model.repository.ConceptLevel1Repository; import eu.dnetlib.is.context.model.repository.ConceptLevel1Repository;
@ -61,9 +62,23 @@ public class ContextRestController {
return contextRepository.getById(ctxId); return contextRepository.getById(ctxId);
} }
@GetMapping("/{ctxId}/categories") @GetMapping("/{parent}/categories")
public Iterable<Category> listCategories(@PathVariable final String ctxId) { public Iterable<Category> listCategories(@PathVariable final String parent) {
return categoryRepository.findByParentOrderById(ctxId); return categoryRepository.findByParentOrderById(parent);
}
@GetMapping("/{level}/{parent}/concepts")
public Iterable<? extends CtxChildInfo> listCategories(@PathVariable final int level, @PathVariable final String parent) {
switch (level) {
case 0:
return conceptLevel0Repository.findByParentOrderById(parent);
case 1:
return conceptLevel1Repository.findByParentOrderById(parent);
case 2:
return conceptLevel2Repository.findByParentOrderById(parent);
default:
throw new RuntimeException("Invalid concept level - valid levels are 0, 1, 2");
}
} }
@PostMapping(value = "/load", consumes = "text/plain") @PostMapping(value = "/load", consumes = "text/plain")

View File

@ -5,7 +5,7 @@ import javax.persistence.Table;
@Entity @Entity
@Table(name = "context_categories") @Table(name = "context_categories")
public class Category extends CtxInfoWithClaim { public class Category extends CtxChildInfo {
private static final long serialVersionUID = -1847175903793410585L; private static final long serialVersionUID = -1847175903793410585L;

View File

@ -5,7 +5,7 @@ import javax.persistence.Table;
@Entity @Entity
@Table(name = "context_cat_concepts_lvl_0") @Table(name = "context_cat_concepts_lvl_0")
public class ConceptLevel0 extends CtxInfoWithClaim { public class ConceptLevel0 extends CtxChildInfo {
private static final long serialVersionUID = -4775331902088912839L; private static final long serialVersionUID = -4775331902088912839L;

View File

@ -5,7 +5,7 @@ import javax.persistence.Table;
@Entity @Entity
@Table(name = "context_cat_concepts_lvl_1") @Table(name = "context_cat_concepts_lvl_1")
public class ConceptLevel1 extends CtxInfoWithClaim { public class ConceptLevel1 extends CtxChildInfo {
private static final long serialVersionUID = -759398689766245784L; private static final long serialVersionUID = -759398689766245784L;

View File

@ -5,7 +5,7 @@ import javax.persistence.Table;
@Entity @Entity
@Table(name = "context_cat_concepts_lvl_2") @Table(name = "context_cat_concepts_lvl_2")
public class ConceptLevel2 extends CtxInfoWithClaim { public class ConceptLevel2 extends CtxChildInfo {
private static final long serialVersionUID = 906131339592862096L; private static final long serialVersionUID = 906131339592862096L;

View File

@ -4,7 +4,7 @@ import javax.persistence.Column;
import javax.persistence.MappedSuperclass; import javax.persistence.MappedSuperclass;
@MappedSuperclass @MappedSuperclass
public abstract class CtxInfoWithClaim extends CtxInfo { public abstract class CtxChildInfo extends CtxInfo {
private static final long serialVersionUID = -9005145235908917048L; private static final long serialVersionUID = -9005145235908917048L;