context apis
This commit is contained in:
parent
a36745ab8b
commit
0855c17f4a
|
@ -18,8 +18,8 @@ import eu.dnetlib.is.context.model.ConceptLevel0;
|
|||
import eu.dnetlib.is.context.model.ConceptLevel1;
|
||||
import eu.dnetlib.is.context.model.ConceptLevel2;
|
||||
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.CtxInfoWithClaim;
|
||||
import eu.dnetlib.is.context.model.Parameter;
|
||||
import eu.dnetlib.is.context.model.repository.CategoryRepository;
|
||||
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) {
|
||||
o.setId(n.valueOf("@id"));
|
||||
o.setLabel(n.valueOf("@label"));
|
||||
if (o instanceof CtxInfoWithClaim) {
|
||||
((CtxInfoWithClaim) o).setParent(parent);
|
||||
((CtxInfoWithClaim) o).setClaim(BooleanUtils.toBoolean(n.valueOf("@claim")));
|
||||
if (o instanceof CtxChildInfo) {
|
||||
((CtxChildInfo) o).setParent(parent);
|
||||
((CtxChildInfo) o).setClaim(BooleanUtils.toBoolean(n.valueOf("@claim")));
|
||||
}
|
||||
o.setParameters(n.selectNodes("./param")
|
||||
.stream()
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
|
||||
import eu.dnetlib.is.context.model.Category;
|
||||
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.ConceptLevel0Repository;
|
||||
import eu.dnetlib.is.context.model.repository.ConceptLevel1Repository;
|
||||
|
@ -61,9 +62,23 @@ public class ContextRestController {
|
|||
return contextRepository.getById(ctxId);
|
||||
}
|
||||
|
||||
@GetMapping("/{ctxId}/categories")
|
||||
public Iterable<Category> listCategories(@PathVariable final String ctxId) {
|
||||
return categoryRepository.findByParentOrderById(ctxId);
|
||||
@GetMapping("/{parent}/categories")
|
||||
public Iterable<Category> listCategories(@PathVariable final String parent) {
|
||||
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")
|
||||
|
|
|
@ -5,7 +5,7 @@ import javax.persistence.Table;
|
|||
|
||||
@Entity
|
||||
@Table(name = "context_categories")
|
||||
public class Category extends CtxInfoWithClaim {
|
||||
public class Category extends CtxChildInfo {
|
||||
|
||||
private static final long serialVersionUID = -1847175903793410585L;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import javax.persistence.Table;
|
|||
|
||||
@Entity
|
||||
@Table(name = "context_cat_concepts_lvl_0")
|
||||
public class ConceptLevel0 extends CtxInfoWithClaim {
|
||||
public class ConceptLevel0 extends CtxChildInfo {
|
||||
|
||||
private static final long serialVersionUID = -4775331902088912839L;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import javax.persistence.Table;
|
|||
|
||||
@Entity
|
||||
@Table(name = "context_cat_concepts_lvl_1")
|
||||
public class ConceptLevel1 extends CtxInfoWithClaim {
|
||||
public class ConceptLevel1 extends CtxChildInfo {
|
||||
|
||||
private static final long serialVersionUID = -759398689766245784L;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import javax.persistence.Table;
|
|||
|
||||
@Entity
|
||||
@Table(name = "context_cat_concepts_lvl_2")
|
||||
public class ConceptLevel2 extends CtxInfoWithClaim {
|
||||
public class ConceptLevel2 extends CtxChildInfo {
|
||||
|
||||
private static final long serialVersionUID = 906131339592862096L;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import javax.persistence.Column;
|
|||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
@MappedSuperclass
|
||||
public abstract class CtxInfoWithClaim extends CtxInfo {
|
||||
public abstract class CtxChildInfo extends CtxInfo {
|
||||
|
||||
private static final long serialVersionUID = -9005145235908917048L;
|
||||
|
Loading…
Reference in New Issue